Unit - II Linux oss - Copy
Unit - II Linux oss - Copy
WOMEN, VANIYAMBADI
SYLLABUS
UNIT II
Introduction: Linux Essential Commands – Kernel Mode and user mode –File
system Concept – Standard Files – The Linux Security Model – Vi Editor –
Partitions Creation – Shell Introduction – String Processing – Investigation
and Managing Processes – Network Clients – Installing Application.
Introduction
Linux is a popular version of the UNIX Operating System. It is open source as its source code is
freely available. It is free to use. Linux was designed considering UNIX compatibility. Its
functionality list is quite similar to that of UNIX.
Linux is an open source operating system (OS). An operating system is the software that directly
manages a system’s hardware and resources, like CPU, memory, and storage. The OS sits between
applications and hardware and makes the connections between all of your software and the
physical resources that do the work.
ls command
The ls command lists the directory content. If no directory is specified, the command will
display the content of the working directory.
pwd command
The pwd command is used to print the path of the current directory.
mkdir command
To create a new directoy, the mkdir command is used. You must specify the name of the
directory. If no path is specified, the directory is created inside the working directory.
echo command
The echo command is used to to output text to the screen. You simply type echo and then the
text you would like to display.
whoami command
The whoami command displays the username of the current user.
cd command
To change the current working directory we use the cd command. You must specify the path of
the directory you would like to access.
Linux file system has a hierarchal file structure as it contains a root directory and its subdirectories.
All other directories can be accessed from the root directory. A partition usually has only one file
system, but it may have more than one file system.
Linux File System or any file system generally is a layer that is under the operating system that
handles the positioning of your data on the storage; without it, the system cannot knows which file
starts from where and ends where.
Standard Files
stdin
The primary input channel for the program. Default source is the user’s keyboard, but it can easily
be switched to be from another process via a pipe ( | ) or a file via a file redirection ( < ).
stdout
The primary output channel for program’s data output. Default destination is the user’s screen, but
it can easily be switched to another process via a pipe ( | ) or a file via a file redirection ( > ).
stderr
Output channel for error messages. Default destination is the user’s screen, but it can be switched
to another process via a pipe ( | ) or a file via a file redirection ( > ).
A third set of permissions is maintained for everyone on the system who is neither the owner nor
in the group associated with a resource. This is commonly referred to as the permissions for 'other'
users.
These security levels, user, group and other, each have a set of permissions associated with
them. Typical permissions are read, write and execute and depending on the type of resource,
these will determine what a given user is allowed to do with the resource.
In this example, the ls -l command is used to show the ownership and permissions of the file
status.sh.
The permissions portion of the output breaks down further to indicate the level of access for the
owner, group and other users. In this example, the owner has read, write and execute, the group
has read and execute and other has only read.
Each user on the system is associated with a primary group but can also belong to additional
groups, adding to the flexibility of Linux security. A user has access rights granted to his or her
primary group as well as any additional groups to which the user belongs.
Though we use user and group names are used to interact with the system, these identifiers are
tracked within the system by ID numbers. The user ID (UID)and group ID (GID) numbers are
associated with user and group names through the /etc/passwd and /etc/group files, respectively.
Vi Editor
The VI editor is the most popular and classic text editor in the Linux family. Below, are some
reasons which make it a widely used editor –
Nowadays, there are advanced versions of the vi editor available, and the most popular one
is VIM which is Vi Improved. Some of the other ones are Elvis, Nvi, Nano, and Vile. It is wise
to learn vi because it is feature-rich and offers endless possibilities to edit a file.
To work on VI editor, you need to understand its operation modes. They can be divided into two
main parts.
Command mode
● The vi editor opens in this mode, and it only understands commands
● In this mode, you can, move the cursor and cut, copy, paste the text
● This mode also saves the changes you have made to the file
● Commands are case sensitive. You should use the right letter case.
Our main objective here is to create a partition. To create a new partition, we use the command
‘n’. This will prompt you to specify the type of partition which you wish to create.
If you wish to create a logical partition, choose ‘l’. Alternatively, you can choose ‘p’ for a primary
partition. For this tutorial, we will create a primary partition.
Now, we will be asked to specify the starting sector for our new partition. Press ENTER to choose
the first available free sector on your system. Next, you’ll be prompted to select the last sector for
the partition.
Either press ENTER to use up all the available space after your first sector or specify the size for
your partition
Sector Type
As shown in the screenshot above, we chose to create a 10 MB partition for this demonstration.
Here ‘M’ specifies the unit as megabytes. You can use ‘G’ for gigabytes.
If you don’t specify a unit, the unit will be assumed to be sectors. Hence +1024 will mean 1024
sectors from the starting sector.
Shell Introduction
A shell program, sometimes referred to as a shell script, is simply a program constructed of shell
commands. Shell programs are interpreted each time they are run. This means each command is
processed (i.e. executed) by the shell a single line at a time. This is different from languages such
as C or C++, which are translated in their entirety by a compiler program into a binary image. A
shell program may be simple and consist of just a few shell commands, or it may be very complex
and consist of thousands of shell commands. The complexity of the shell program is in the hand
of the programmer. In general, a shell program can be characterized by:
As stated, a shell program is merely a file containing shell commands. Thus, if we wanted to write
the venerable "hello world" program as a shell script, we could do the following:
1. use the editor to create the program, for simplicity we'll call hw (recall file extensions are
not mandatory)
$ vi hw [Enter]
6. once the problem above is fixed, we run the script and see the following:
7. $ hw [Enter]
Hello World!
You have now written your first successful shell program.
String Processing
Shell programming is heavily dependent on string processing. The term string is used generically
to refer to any sequence of characters; typical examples of strings might be a line of input or a
single argument to a command. Users enter responses to prompts, file names are generated, and
commands produce output. Recurring throughout this is the need to determine whether a given
string conforms to a given pattern; this process is called pattern matching. The shell has a fair
amount of built-in pattern matching functionality.
Listing Process:
# ps (displays the following)
# pgrep -u username
(to see PID related to specific user)
#pidof crond
(to see PID of specific process)
Signals: Signals are messages that are sent to processes with a command like kill.
The advantage of signals is that they can be sent to a process even if it is not attached to a terminal.
So if a web server or a graphical program whose interface has “frozen” can still be shut down by
sending appropriate signal.
CTRL + C also terminate the process, which send an interrupt (INT) signal to a process.
If a process doesn’t terminate using above method, you can use KILL signal.
(Remember it should only be used when the above method doesn’t work. Using KILL signal on
a routine basis may cause zombie process and loose data)
5. Scheduling Priority:
Every running process has a scheduling priority, Whoever has got higher priority, gets more
attention of the CPU.
The niceness value defaults to zero(0) but can be set from -20 (least value, highest piority) to 19
(highest value, least priority)
To set the niceness value to a specific value when starting a process, use nice -n as
following:
nice -n 13 vim file.txt (to run vim at 13 niceness value)
nice -n -13 vim file.txt (to run vim at -13 niceness value)
To modify the niceness value of running processes, use renice command as following:
renice 15 PID (Where PID is process ID of running process)
renice -15 PID
Running top presents a list of the processes running on your system, updated every 5 seconds, you can
use keystrokes to kill, renice, colorize processes, define the order to display etc. Press the ? key while
in top to view the complete list of hotkeys.
Job Control
Jobs running in the foreground can be suspended: temporarily stopped, without being killed. To
suspend a job, Press Ctrl + z. Once a process is suspended, it can be resume in the background
using the bg command or resumed in the foreground using the fg command. When the job
resumes, it will continue executing from the point at which it was suspended. It will not have to
start over from the beginning.
Network Client
Network Client is a software that runs on a client computer and allows it to establish connectivity
with services running on server computers. In Microsoft Windows 95 and Windows 98, the
network client is one of several components that can be installed to provide connectivity with
different kinds of networks. Without the appropriate client software, a workstation cannot access
files and print resources or other resources on a network server.
Installing Application
The RPM Package Manager
All software on a Red Hat Enterprise Linux system is divided into RPM packages which can be
installed, upgraded, or removed using the RPM package manager.
No such thing as a patch. It is common on other platforms to have operating system updates
released as software objects (eg. “service packs”) which represent incremental changes to a large
number of installed component packages. RPM never does this. If part of any given software
package is changed as part of an errata or bug fix, then that entire package will be re-released in
its entirety at a new version. The implications are that the installed state of an RPM-managed
system can be described as the version number of all the installed components.
Software to be installed using rpm is distributed through rpm package files, which are essentially
compressed archives of files and associated dependency information. Package files are named
using the following format:
name-version-release.architecture.rpm
The version refers to the open source version of the project, while the release refers to Red Hat
internal patches to the open source code.
The above command will search the configured repositories for a package named firefox, and if
found will install the latest version, pulling in dependencies if needed.
[root@stationX ~]# yum remove mypackage
The above command will try to remove the package named mypackage from your system. If any
other package depends on mypackage yum will prompt you about this, giving you the option to
remove those packages as well.