You are on page 1of 103

Unix

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Topics of Discussion
 UNIX Overview
 BASIC UNIX commands
 Regular Expressions
 Understanding UNIX Security
 Understanding a process
 Shell Scripting
 Return Codes and Traps
 Basic UNIX commands

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Introduction to Unix Operating System

 What is Unix?
 Need for Unix in today’s world?
 Evolution of Unix.
 Flavours of Unix.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Features Of Unix.

 The important characteristic features


are
 Multiuser,Multitasking
 Portability.
 Security.
 Pipes.
 Redirection Tools.
 Stable and Reliable

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Features Of Unix (Contd.)
 Shell programming.
 Hierarchical File System.
 Provides virtual memory support
 Devices are treated as files
 Supports the X-Window system
 Provides more than one type of shells
(command interpreters)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


System Architecture.
 Major components of Unix are :
 Kernel
 Shell
 Utilities
 User Applications

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


System Architecture.
User
User

SHELL
SHELL
UNIX OTHER
COMMANDS APPLICATIONS

HARDWARE

DATABASE KERNEL COMPILERS


PACKAGES

SHELL
SHELL

User User

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Function of a shell
 Displays a prompt where the user can
enter a new command.
 Validates the command entered by the
user.
 Acts as a command interpreter.
 Creates a new process using fork() system
call.
 Executes the command using exec()
system call.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Function of a shell

 A shell also provides a programming


environment through a combination
of :

 standard Unix utilities and commands

 built-in shell commands

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Structure of Unix File System.
/ (root)

home bin dev var tmp lib usr opt


etc
sh ls tty lp
passwd shadow

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Understanding pathnames

 A pathname specifies the location of a


directory or a file within the file system.

 A pathname consists of a series of


directory names separated by slashes
( / ) that ends with a directory name or a
file name.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Absolute Path and Relative Path.

 The Absolute Path.


 The entire pathname starting from root(/).
 Example : /home/trng10/file1.
 The Relative Path.
 The path relative to your present working
directory.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Types of file
 Ordinary file ( - )
 Directory file ( d )
 Device or special file (b or c)
 Linked file ( l )

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Files and directories
 In Unix, each file is a series of bytes
without any structure (format). The
directory is the only file that has a
structure imposed on it.

 Each file has one or more names. Each file


is also stored in a directory. The directories
are stored in the file system.

 A file system is the way of organising files


& directories on storage media
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
File attributes
 In Unix, each file has number of attributes
associated with it. Some of these are:

 File type
 File permissions
 File owner user ID and group ID
 File size
 Date/time of creation, last update and last
access
 Number of hard links

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File names
 A file name can contain any character
except the following because these have
special meaning to the shell:
Slash ( / )
Backslash ( \ )
Ampersand ( & )
Left- and right-angle brackets (< and
>)
Question mark ( ? )
Dollar sign ( $ )
Left bracket ( [ )
Asterisk ( * )
Tilde ( ~ )
Vertical bar or pipe symbol ( | )
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
File names
 You may use a period or dot ( . ) in the
middle of a file name. If you use a dot at the
beginning of the file name it will be hidden
file.

 The maximum length of a file name depends


upon the file system used. Most new file
system allow a maximum length of 255
characters (the default). Older file systems
allow a maximum file name length of only 14
characters.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Finding the type of a file
 Use the file command to see what kind of data a file
contains. The file command displays whether the file
is one of the following:

 A directory
 A text file
 A FIFO (pipe) special file
 A block special file
 A character special file
 Source code for the C or FORTRAN languages
 An executable (binary) file
 An archive file in ar format & An archive file in
zip format

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Finding the type of a file
 An archive file in extended cpio or extended
tar format
 A compressed data file in gzip format
 A file of commands text (shell script)
 An audio file in .voc, .iff, or .wav format
 An image file in TIFF, GIF, MPEG, or JPEG
format
This command is especially useful when you
suspect that a file contains a compiled
program,
audio data, or image data. Displaying the
contents
of these types of files can produce strange
results
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
Understanding directories
 In Unix, a directory is a file that has a
number of entries. Each entry contains:

 A filename
 The I-node number of the file

 Every directory contains at least two entries:

 Filename of .. (dot dot)


 Filename of. (dot)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Understanding directories
 In the C shell and the Korn shell, you may
also use a tilde ( ~) at the beginning of
relative pathnames.

 The tilde character used alone specifies your


home directory. The tilde character followed
by a user name specifies the home directory
of that user. For example,
$ cd ~user1
$ cd ~user1/xyz

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Unix User Account
 Your Unix user account will have a login
name and most probably a password.

 In addition, a number of other attributes


are associated with a user account in Unix.
The four most important attributes are:
 Home Directory
 Login Shell
 User ID
 Group ID

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Login Process
 Once you log in, Unix creates a process for
you, and runs the login shell as a
program in that process.

 For the login shell process, Unix makes


your home directory as the current
directory.

 Therefore, after login, by default, you will


be working with your home directory.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Login Process
 When you log into Unix, your login shell
also executes a startup script for you
from your home directory.
 The name of this script depends upon
the login shell. For Bourne shell, this file
is “.profile” file. For C-shell, this file is
“.cshrc” file.
 To customize your login environment,
you can modify these startup scripts.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Using Unix Commands

 Types of commands

 Built-in commands :
 These commands are part of the shell
 External commands
 These commands are separate programs
or files that are stored under a filesystem

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Unix Command Structure

Unix Command line structure.


command [options] [arguments]

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands.
ls - List contents of a directory.
ls [option] [filenames]

cat - Concatenate and display files.


cat [file ...]
cat > filename

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands.
cp - Copy files.
cp [option...] [file1] [file2]
Option : -i , -r

mv - Move or rename files.


mv [option...] [file1] [file2]
Option : -i interactive

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands.
pwd - Display Working directory.

passwd - to set password

cd - Change Working directory.


cd [Directory]

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands
mkdir - Make Directories.
mkdir [options] DirectoryName
Option : -p

rmdir - Remove Directories.


rmdir DirectoryName

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands
rm - Remove files or directories.
rm [option...] file ...

date - to display date and time


date option/s

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands
cal – Calendar.
cal [options] [arguments]

who – Displays the users connected


who
Which or whereis - to find location of any command
which command_name

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


General Unix
Commands
more – Allows display page wise.
more [files]

who am i – Display username.


hostname - Display 's computer name
clear - to clear screen
banner - to increase font size
banner hello

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Getting Help

 To learn more about commands, see the man


pages.

 When hard copy documents are not available, yo


can access online documentation by using the
following commands:

 The man command displays online reference pages.


 The apropos command displays a one line summary
of each command pertaining to a specified subject.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Getting Help
 The apropos command and man -k
command are useful tools if you forget a
command name. These commands require
access to the whatis database. This
database must be installed.

 Both these commands let you enter a


command description in the form of
keywords. The commands then list all the
reference pages that contain any of the
keywords.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Getting Help
 Assume that you cannot remember the
name of the command that displays who is
logged in to the system.

 To display the names and descriptions of


all man pages that are related to users who
are logged in, enter one of the following:

$ apropos "logged in"


or
$ man -k 'logged in'

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Printing files
 If your system has more than one printer,
use following format to specify where you
want the file to print:
lpr -P printername filename
The printername is the name of a printer.

 Use following format if u want to take


printout from default printer
cat filename > /dev/lp0
cal > /dev/lp0
ls > /dev/lp0

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Viewing Print Queues
 To see the position of the request in the
print queue, use the lpq command.
# lpq
 If there are no requests in the print queue,
the system responds with the following
message:
no entries
 If there are entries in the queue, the system
lists them and indicates what is currently
being printed.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Viewing Print Queues

 The lpq displays following for each print


job:
 Its position in the queue
 Its owner
 Its job number
 Name of the file
 Size of the file in bytes

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Standard Files.
Standard Input
This file is opened by shell to accept information.

Standard Output
This file is opened by shell to direct output.

Standard Error
This file is opened by shell for writing error
messages.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


I/O Redirection
 Redirection input operator (<)
 Redirection output operator (>)
 Redirection append operaror (>>)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Descriptor
 Standard input (0)

 Standard output (1)

 Standard error (2)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Regular Expressions.
What is it?
String of ordinary and metacharacter which can be
used to match more than one type of pattern.
Metacharacters are characters that shell interprets
as having a special meaning.
Uses character set
< , > , | , ; , ! , ? , \ , " , ' , ` , # , * , [] , ^ ,
$ , {}, etc.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


The Shell
Metacharacters.
* - Matches all filenames in current directory.
? - Matches a single character.
[abc] - Matches a single character –either a,b or c.
[!abc] - Matches a single character – which is not a, b or c.
[a-c] – Matches a single character which is within the
range of a and c.
^abc – Matches the pattern abc at the beginning of the line.
abc$ - Matches the pattern abc at the end of the line.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Filenames and Wildcards
Expression Matches
[a-zA-Z] All lower- and uppercase letters
[a-zA-Z0-9_-] All letters, all digits, underscore, and dash

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Special Characters and
Quoting
 Table 1.6: Special Characters
Character Meaning
~ Home directory
# Comment
$ Variable expression
& Background job
* String wildcard
( Start subshell
) End subshell
\ suppress meaning of any metacharacter
| Pipe

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Special Characters and
Quoting
Character Meaning
[ Start character-set wildcard
] End character-set wildcard
{ Start code block
} End code block
; Shell command separator
‘ Strong quote
“ Weak quote
< Input redirect
> Output redirect
/ Pathname directory separator
? Single-character wildcard

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Control Keys
CTRL-C intr Stop current command
CTRL-D eof End of input
CTRL-S stop Halt output to screen
CTRL-Q Restart output to screen
DEL or [CTRL-?] erase Erase last character
CTRL-U kill Erase entire command line
CTRL-Z susp Suspend current command

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Next Step

 The vi Editor.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Editor in Unix
Need for editor in Unix.
Types of editor
Line Editor.
ed : UC Berkeley
ex : Powerful than ed, Bell Systems
Full Screen Editor.
vi (stands for visual).
vim – vi improved
emacs (GNU)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


The vi Editor.

Modes of working:
Command Mode.
Insert Mode.
Escape Mode.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


vi Operating modes.

i, I , o, O, a, A ..
Command mode

Enter esc Insert mode


:

Escape mode :q

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Vi editor commands.
To move around
h to move one character left
j one line down
k one line up
l to move cursor one character right
^D to move to end of a screen
^U scroll up
G end of a document
0 insert blank line above current line
$ to move cursor end of a line
^ to move cursor beginning of a line

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Vi editor commands.
 Inserting/Deleting text
 i inserting text
 a to append cursor one position to the right
 I to move to beginning of a line
 A to move to end of a line
 r replace one character at cursor
 R replaces whole line
 o inserts a blank line below current line
 O inserts a blank line above current line
 dd deletes whole line
 dw deletes one word
 d$ deletes text from cursor to end of a line in
forward
or D direction
 x deletes one character at cursor
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
Vi editor commands.
 Changing/Replacing text.
 ~ converts small to upper or upper to small case
 J joining lines
 uundo
 . redo
 yy to copy whole line
 yw to copy one word
 ppaste
 P paste

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Vi editor commands.
 File manipulation.
 :w save and continue editing
 :wq save and exit
 ZZ save and exit
 :w! save and continue editing
 :q quit when no changes are made to a file
 :q! Quit without saving
 :![command]
to issue unix commands from within editor

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Searching a pattern.
/pattern
Searches forward for first occurrence of a
pattern.
?pattern
Searches backward for first occurrence of a
pattern.
n
Repeats the last search.
N
Repeats the last search command in opposite
direction.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Pattern Substitution.
:s/ptn1/ptn2
Replaces first occurrence of ptn1 with ptn2.
: s/ptn1/ptn2/g
Replaces all occurrences in the current line.
: m, n s/ptn1/ptn2/g
Replaces all occurrences in lines m to n.
: ., $ s/ptn1/ptn2/g
Replaces all occurrences from current line to end of
file.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Customizing vi.
The set command.
:set all
:set nu
:set showmode
:set list
:set ic
:set autoindent
:set tabstop=5
The abbr command.
:abbr ut unix training

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Handling
vi file1 file2 file3
multiple files.
Opens all files one after another.

:n
Permits editing of next file in the buffer.

:N
Permits editing of previous file in the buffer.

: rew
Permits editing of first file in buffer.

: args
Displays names of all files in the buffer.

:f Displays the name of the current file.


© Affiliated Computer Services, Inc. (ACS) 2007, 2008
Text Processing Utilities
head
Display the first count lines of files.

head [-count] [file ...]

tail
Display the last count lines of a file.

tail [+/-[number] file

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Text Processing
Utilities(contd)
tr - Translate characters.
Translates character/characters.
tr [option...] string1 [string2]

sort
Ordered arrangement.
sort [option] file

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Text Processing Utilities
-(Contd…)
cut
Cuts selected fields of each line of a file.
cut –flist [-d char] [file1 file2 ...]

paste
Merging the corresponding lines of given files.
paste file1 file2….

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Text Processing Utilities
-(Contd…)
cmp
Compare 2 files.
cmp file1 file2

comm
Compares 2 sorted files.
comm file1 file2

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Text Processing Utilities
(contd).
diff
Reports the differences between files.
diff file1 file2

grep
Pattern searching in a file.
grep [option...] pattern [file...]

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Text Processing Utilities
(contd).
uniq
To remove adjacent repeated lines.
uniq [option] [file]

wc
Counts and displays the number of lines, words and
characters in a file.
wc [option...] filename...

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Handling
Commands (contd).
find
Search for files.
find [PATH] [EXPRESSION]

file
File Type determination.
file FILES

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Links
Link is a pointer
It points to some object.

Types of links:

-Soft or Symbolic link (indirect pointer)

-Hard link (direct pointer)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Hard Links
 When you create a hard link, you are
providing another name for the same file.
 Hard links let you link only files in the same
file system.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Soft Links

 Soft links or symbolic links let you link


both files and directories.
 linking both files and directories
across different file systems is possible
 A symbolic link is actually a distinct file
that contains a pointer to another file or
directory.
 Unlike a hard link, a soft link is actually
only a link.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Inodes and Linking.
A directory
FILENAME INODE Another directory
NUM
FILENAME INODE
file1 0221 NUM

file2 0412 name1 0221


file3 0981

• File1 and name1 are links


with same inode numbers
Inode
block #0412 #0221

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Creating links
 ln - Make link to files.
 Hard link
 ln file1 [file2 ...] target

 Soft link
 ln -s file1 file3

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Deleting Links

 unlink command

It can delete both hard and soft link

Ex:-
# unlink linked_filename

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Security.
Classes of users for a file.
Owner
Group
Others

Classes of Permissions for a file.


Read (r)
Write (w)
Execute (x)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Security.
Two modes of setting file permissions
Absolute Mode (Octal Integer)
Symbolic Mode (String)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Permission -
Absolute Mode.
 Uses numbers for mentioning the permissions.

Owner Group Others


r w x r w x r w x

4 2 1 4 2 1 4 2 1

rwxrwxrwx

Owner Group Others

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Permission –
Symbolic Mode.
Uses characters & arithmetic operators for
mentioning the permissions.
Example
u+rx – Indicates the user has read and execute
permissions.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


chmod - Setting
Permissions
chmod
Used for setting file and directory permissions.
Syntax.
chmod [0-7][0-7][0-7] filename (Absolute Mode)
chmod [ugo][+-][rwx] filename (Symbolic Mode)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File Permissions -
umask
umask
Stands for user creation mask.
Sets default permissions for a newly created file and
directory.
Default value is 022.
The value can be changed.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Default File Permissions

 Calculate system default file permissions


6 6 6 - System wide default
permissions
-0 2 2 - Denial ‘mask’ set by UMASK
6 4 4 - Resultant permissions that will
be set on all files created
(-rw-r—r--)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Default Directory
Permissions
 Calculate system default directory
permissions
7 7 7 - System wide default
permissions
- 0 2 2 - Denial ‘mask’ set by UMASK
7 5 5 - Resultant permissions that will
be set on all directories
created (drwxr-xr-x)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


File & Directory
Permissions
System wide default permission for a file
rw-rw-rw (666)
System wide default permission for a directory
 rwxrwxrwx (777)

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Changing Ownership
chown
Changing ownership for a file.
Can be done only by the root or administrator.
Syntax
chown username file.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Changing Group
chgrp
Changing group for a file.
Can be changed by the owner of the file.
Syntax
chgrp groupname file.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Unix Security -
Password
The two important files that are used frequently for
password authentication are
/etc/passwd
/etc/shadow
These files are used whenever a user logins in the
system.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Unix Security -
/etc/passwd
Unix stores the user information in the passwd file.
It contains records that define login accounts
and attributes for all system users. This file
can be altered only by a user with super-
user privileges.
It contains 7 fields separated by colon (:)
Username
Encrypted Password
User-id
Group-id
Comments
Home Directory
Shell © Affiliated Computer Services, Inc. (ACS) 2007, 2008
Unix Security -
/etc/shadow
Stores the encrypted password.
Also called “Shadow Password File”.
Can only be viewed by the super-user (root).

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Unix Security -/etc/group
 The /etc/group file defines login accounts for
all groups using the system. This file can be
altered only by a user with super-user
privileges.

 Each entry in this file defines the login


account of one group. Groups provide a
convenient way to share files among users
who are working on the same project.

 The format of each entry is :


groupname:password:GID:user1[,user2,...,
userN ]
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
Sticky Bit
When the Sticky bit for directory is set, there can be
no deletion or overwriting of existing files in the
directory.
Syntax
chmod o+t directoryname or
 chmod 1[0-7][0-7][0-7] directoryname

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Set UID bit.
Allows the user to temporarily assume the
permissions of the file owner’s .
Syntax
 chmod u+s filename
 chmod 4[0-7][0-7][0-7] filename

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Set GID bit
 Allows the group to temporarily
assume the permissions of the file
group owner’s
 Syntax
chmod g+s filename
chmod 2[0-7][0-7][0-7] filename

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Becoming another user - su
su – Substitute user-id.

Used to switch from one user a/c to another without logging


off.

An user can login as super-user without the need of logging


off from the system.

The su command lets you alter your identity during a


login session.

A reason for altering your identity is to be able to


access files that you do not own.
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
Becoming another user - su
 The su command lets you log in to another user's
account only if you know that user's password.

 The format of the su command is:


su - username

 Use the whoami command to check su logged


user.

 To log-out from su logged user, press Ctrl D or


enter the exit command.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


The super-user concept
 Every Unix system has a super-user who
has permissions that supersede those of
ordinary users. This super-user is often
referred to as root.

 The root user has absolute power over the


running of the system. This user has
access to all files and all devices and can
make any changes to the system. The root
user is said to have super-user privileges.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


The super-user concept
 The following is a list of tasks ordinarily
performed by root users:
 Edit files not usually changeable by ordinary
users (for example, /etc/passwd)
 Change ownership and permissions of all files
 Execute restricted commands like mount or
reboot
 Kill any process running on your system
 Add and remove user accounts
 Boot and shut down the system
 Back up the system

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


The super-user concept
 To become a root user, use the su
command. You must know the password for
the root user. The format is:
su
 The following example shows how to
become a root user :
$ su -
Password: ...
#
 The # prompt typically indicates the root
user.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Process

 Process is an instance of a program in


execution.
 A program is a set of instructions that a
computer can interpret and run.
 While a program is running, it is called a
process. Unix assigns a process identifier
(PID) to every process.
 When a process begins executing, Unix
opens three files for the process: stdin
(standard input), stdout (standard output),
and stderr (standard error).

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Process
 To view process status, use ps command
$ ps

 Unix allows you to run a number of


different processes at the same time. These
different processes can be from one or
multiple users.

 you can run both foreground and


background jobs simultaneously.

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Types of processes
 Foreground process:
- requires user interruption.
 Background process:
- runs in background.
- daemon processes are background process
- " & " is used to send any process in the
background
- to check background process , jobs command
is used
$ jobs
- fg command is used to transfer background
process to foreground
$ fg %job_number
© Affiliated Computer Services, Inc. (ACS) 2007, 2008
Suspended jobs
 Processes breaked in between while
running are suspended jobs
 To view suspended jobs, ps or jobs
command can be used.
 Suspended jobs can be taken in foreground
or background by using fg or bg command
$ bg %job_number

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Process Oriented
Commands.
 nohup
 Continue execution even after logout.
 nohup command [arguments] &
 Ex: nohup sort file1 &

 nice
 Execute commands with lower priority.
 nice [option] command [arguments]

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Process Oriented
Commands
 kill
• Send signal to processes.
• kill -[option] pid

© Affiliated Computer Services, Inc. (ACS) 2007, 2008


Thank You!

© Affiliated Computer Services, Inc. (ACS) 2007, 2008

You might also like