Académique Documents
Professionnel Documents
Culture Documents
PLMi
Unix History
Evolved at AT&T Bell Labs in late sixties. Ken Thomson, Rudd Canaday, Doug McIilroy, Joe Ossanna and Dennis Ritchie - writers of Unix. Originally written as OS for PDP-7 and later for PDP-11. Liberal liscensing: Various versions. System V in 1983 - Unification of all variants.
Features of UNIX
Features of UNIX
Shell user Other Application and system software Unix commands Kernel Hardware shell
shell
user
Database Packages
Features of Unix
Services Provided :
Process Management
Communication
Features of Unix
Services Provided :
File Management
Aspects related to files like Creation & Deletion, File security etc.
File System
Hierarchical Structure Consistent Treatment of Data: Lack of file format The Treatment of Peripheral Devices as Files Protection of File Data
File System
Root (/)
bin
<Files>
dev
<Files>
etc
<Files>
mnt
tmp
<Files>
unix
bin
usr
Kumar Sharma
<files>
prog <files>
safe <files>
File System
/ bin commonly used UNIX Command like /usr/bin who, ls, cat, wc etc. are stored here /dev - contains device files of all hardware devices /etc - contains those utilities mostly used by system administrator e.g. passwd, chmod, chown
File System
/tmp - used by some UNIX utilities especially vi and by temporary files /usr - contains all the files created by user, including directory /unix - kernel
File System
File Types
File System
Consists of Sequence of Logical Blocks (Each block: Multiple of 512 k bytes) An Installation may have several physical disk units each containing one or more file system Data from another File System can be Accessed by Mounting that File System
File System
File System
Size
# of Files that can be Stored Free Space Information
Inode Information
File System
File System
Data Block : File Data & Administrative Data: stores actual contents of file Inode Table Fields : File Owner Identifier - Owner & Group id File Type - Regular, Directory, Character / Block / Pipe
File System
File Access Permissions rwx rwx rwx user group others Date & Time - Last File/Inode Modified/Accessed No. of Links Disk Addresses File Size
File Permissions
Associated with every file, useful for security. 3 categories of users Owner (u) Group (g) Others (o) Access permissions Read (r) Write (w) Execute (e)
$man <command>
$ pwd
/usr/Kumar/Prog
Listing directory contents - ls command e.g. $ ls a.out chap1 chap2 test test.c $
Options available in ls
Option Description
-x Displays multi columnar output (prior to Release 4) -F Marks executables with *and directories with / -r Sorts files in reverse order (ASCII collating sequence by default) -l The long listing showing seven attributes of a file -d Forces listing of a directory -a Shows all files including ., .. And those beginning with a dot
Options available in ls
Option Description
-t -R -u -i -s
Sorts files by modification time Recursive listing of all files in sub-directories Sorts files by access time (when used with the -t option) Shows i-node number of a file Displays number of blocks used by a file
1 Kumar group 44 May 9 09:08 dept.h 1 Kumar group 212 May 9 09:08 dept.q 1 Kumar group 154 May 9 09:08 emp.h
Consider first entry Field1 --> mode - rwx rwx rwx --> user permissions --> group permissions --> others permissions
File type
d c b
--> regular file --> directory file --> character - read --> block read
- indicates number of links - File owner id - Group id - File size in bytes - Date/time last altered - Filename
Displaying and Creating Files - cat command $ cat dept.lst 01|accounts|6213 02|admin|5423 : 06|training|1006
Scrolling of large files can be freezed by pressing <ctrl s> and resumed by <ctrl q>
$ cat chap1 chap2 - display contents of chap2 immediately after displaying chap1
$ cat > test Type here the text contents After typing the entire text Press <ctrl d> to save and exit <ctrl d> $ cat chap1 chap2 - display contents of chap2 immediately after displaying chap1
Copies a file or group of files e.g. $ cp chap1 temp/chap2 Option - i (interactive) $cp - i chap1 chap2 cp: overwrite chap2 ?y Option -r (recursive) to copy entire directory $cp - r temp newtemp
To delete files $ rm chap1 chap2 chap3 $ rm * Are you sure? y Option - i (interactive delete) $ rm - i chap1 chap2 chap1 : ? y
To rename: mv command Used to rename file or group of files; as well as directories $ mv chap1 man1
e.g.
$ mv temp doc
e.g.
$ mv chap1 chap2 chap3 man1 will move chap1, chap2 & chap3 to man1 directory
To alter file permissions Format : chmod <category> <operation> <permission> <filenames> Category Operations Attribute u-user +assigns permission r-read g-group -remove permission w-write o-others =assigns absolute permission x-execute a-all
e.g.
e.g.
$ chmod u+x note $ ls - l note -rwx r-- r -1 $ chmod ugo+x note $ ls - l note -rwxr-xr-x note
note
e.g.
$ chmod u-x, go+r $ chmod u+x note $ chmod o+wx note $ chmod ugo=r note
note note1
note2
Octal notation
describes both category and permission similar to =operator (absolute assignment) read permission - assigned value is 4 write permission - assigned value is 2 Execute permission - assigned value is 1
e.g. $ chmod 666 note will assign read & write permission to all
e.g.
$ chmod 777 note will assign all permissions to all $ chmod 753 ? note
e.g.
To create a directory - mkdir command Creates a directory e.g. $ mkdir doc e.g. $ mkdir doc doc/example doc/data e.g. $ mkdir doc/example doc - will give error - Order important
rmdir command Used to remove directory Only empty dir can be deleted More than one dir can be deleted in single command Command should be executed from at least one level above in the hierarchy
e.g.
$ rmdir doc $ rmdir doc/example doc $ rmdir doc doc/example - will give error
infile
Allows user to view a file one screen at a time Syntax : more <options <+linenumber> <+/pattern> <filename>
more continued
: appears after displaying screen <spacebar> or <enter> - next screen q - quit n - switch to next file on command p - switch to previous file f - displays filename and line no. /pattern - to locate line with pattern ! - to run command
more continued
:f
=
Description Skips to kth next file that has been specified in the command line Skips to kth previous file that has been specified in the command line Displays current filename and line number Displays current line number
more continued
Command spacebar ks kf ,
/pattern
Description Displays next screen Skips k lines forward Skips k screens forward Reverts to beginning of file if no search made, or to point where last search was made Searches for pattern forward
more continued
Command n v . ! cmd q
Description Repeats last search forward Starts up the vi editor Repeats previous command Executes the Unix command cmd Exits from more
To compare two files & echo first mismatch option -l gives detailed list of byte no. and different byte in octal e.g. $ cmp note1 note2 note1 note2 differ : char3, line1 $ cmp - l note1 note2 3 143 145 6 170 167 7 171 170
To compare two sorted files displays 3 - columnar output first column - lines unique to first file second column - lines unique to second file third column - line common to both files option -1, -2, -3 can be used to display specific column only
Display file differences Display which lines in one file have to be changed to make both files identical
Lists the octal value (ASCII) of any file content used to display non-printing character options b to display 16 byte of data on each line c to display character above octal value e.g. $ od - bc odfile
Lists the octal value (ASCII) of any file content used to display non-printing character options b to display 16 byte of data on each line c to display character above octal value e.g. $ od - bc odfile
Creates poster by blowing up its arguments maximum ten characters in a line e.g. $ banner UNIX $ banner UNIX IS HERE
Displays calendar of a particular month/ year any calendar from year 1 to 9999 e.g. $ cal 1991 $ cal 01 1991
Displays system date number of options available option m - month h - month name d - day of month y - last two digit of the year H - hour M - minute S - second
option
( cont.. )
T a r
e.g.
$ date Fri Dec 7 15:00:21 EST 1990 $ date +%m 12 $ date +%h%m Dec 12
Displays current users of the system displays logname, terminal no., login date and time $ who $ who am i logname of the user
Spooling
Job No
$ lp <file>
tr command
translation of characters
squeeze spaces ( -s )
$ tr s < file1 $ tr [a-z] [A-Z] < file1
find command locate files find <path list> <selection criteria> <action> The following command will locate all the .profile files in the system $ find / -name .profile -print
nl command This command elaborates schemes for numbering lines. $ nl file1.txt This command starts numbering lines from 40 increment value is 7 and width of numbers is 2. ( max 6 allowed ) $nl -w2 -v40 -i7 file1.txt
tty - displays device name of the terminal stty -a - displays current settings stty can also be used to change the setting To use <ctrl c> as interrupt key instead of <Del> key $stty intr \^c
Shell
- widely used
Korn Shell
sh indicates
- Bourne Shell
Working of shell
Issues a $ prompt & waits for user to enter a command After user enters command, shell scans & processes the command. The command is passed on to the Kernel for execution & the shell waits for its conclusion. The $ prompt appears so that the user can enter next command.
* : To match any number of characters ? : To match with a single character [] : Character class; Matching with any single character specified within [] ! : To reverse matching criteria of character class.
\ : To remove special meaning attached to metacharacters ; : To give more than one command at the same prompt
Shell redirections
Every Unix command has access to: Standard input Standard output Standard error
Shell can redirect I/p, o/p or error to any physical file using meta characters <, > & 2>
Shell redirections
Examples: $ ls > temp $ wc < file1.txt > result $ cat nonexistantfile 2> err
Pipe - allows stream of data to be passed between reader & writer process The data that the first processor writes into the pipe is input to second process $ who | wc-l $ ls | wc -l $ ls | wc -l > fcount
tee - standard output can be saved in a file as - can be placed anywhere in pipeline e.g. $ who | tee user.lst kumar tty01 May 18 09 : 32 sharma tty02 May 18 11 : 18 tiwary tty03 May 18 13 : 21 e.g. $ who | tee user.lst | wc-l 3
well as displayed
Command Substitution
Command enclosed in backquotes (`), the shell executes the command first, and the enclosed command text is replaced by the output of the command e.g.$echo The date today is `date` The date today is Fri 27 00:12:55 EST 1990 $echo The date today is; date - issues command echo and date sequentially
Command Substitution
e.g.
$echo There are `ls | wc - l` files in current directory $cal `date +%m 19%y`
echo Command
Displays argument e.g. $echo GOOD Morning GOOD Morning $echo \* * $echo * *
echo Command
escape sequence to manipulate cursor position \t : tab \f : formfeed \n : newline \c : cursor immediately after argument e.g. $echo Enter Your Name : \c Enter Your Name : $_
echo Command
accepts ASCII Octal values e.g. $echo \007 < beep hear:
Shell Variables
User variables can be defined no type declaration or initialization Format : variable=value Value is of string type No space preceding and following =operator
Shell Variables
Evaluated by prefixing variable name with $ multi word assignment must be quoted e.g.1 $x = 37 $echo $ x 37
Shell Variables
e.g.2 e.g.3
$msg = You have mail have not found $msg = You have mail $echo $msg You have mail
Shell Variables
$msg = You\ have\ mail $echo $msg You have mail $x = aa $y = bb $echo $x$y aabb
Shell Variables
$echo Amount = $1000 $echo Amount = \$1000 - both will display : Amount =$1000 $echo Amount = $1000 Amount=000 - here shell evaluated variable $1 as double quoted
Shell Variables
$p = `pwd` $echo $p $echo ${fname} emp.sh $echo ${fname}x emp.shx
Simple Filters
Central tools of Unix toolkit useful text manipulators both horizontal & vertical filters available
head Command
Displays the beginning of one or more file s e.g. $head -3 emp.lst will display first 3 lines if number not specified (default) 10 lines $head -2 emp.lst dept.lst
tail command
displays the end of a file default - display last 10 lines $tail -3 emp.lst displays last 3 lines $tail +50 emp.lst displays till end of file starting from line no. 50 OR tail -n +2 emp.lst
tail command
$tail -15c emp.lst display last 15 characters
Simple filters
Cut :
e.g.
cuts the file emp.lst vertically from column 6 to 22 and from column 24 to 32 $cut -c-5, 10-15, 25 - emp.lst implies 1-5 implies 25 - end of file
Simple filters
Cut :
-d option to specify delimiter can be used with -f option which specifies field no. default delimiter is tab cut selects entire line if not properly delimited
$cut -d | -f 2,3 emp.lst $cut -d | -f 1,5- empl.lst | tee temp
Simple filters
Paste :
paste more than one file laterally $paste file1 file2 <file1> <file2> delimiter can be inserted between two files $paste -d | file1 file2
Sorting a file
Reorders a line in a ASCII collating sequence sorting can be done on a field delimiter can be specified, -t option $sort -t | +1 emp.lst
+1indicates sort after skipping first field i.e. on 2nd field Or $sort t | k 2 emp.lst sorting in reverse order -r option $sort -r +1 emp.lst
Sorting a file
output filename can be specified as argument $sort -0 sortedf emp.lst -c (check) option to check if sort successful. No message indicates sort successful char position can be specified $sort -t | +4.6 - 4.9 emp.lst
will sort 7th & 8th column of field 5 Or $sort t | k4.6, 4.9 emp.lst
Sorting a file
$sort -m file1 file2 file3
Uniq Command
removes duplicate records (-d option) $uniq dept.lst $sort dept.lst | unique - uniqlst -u option if only unique records to be listed -d if only one copy of repeated records to be selected
Editors
Three Types Line Editor - ed, ex Screen Editor - vi Stream Editor - sed
vi Editor
Three Modules :
i, I, a, A, r, R, o, O, s, S
Command Mode
: <Enter> sh <Esc>
ex Mode
Command rch R s
Function Replaces single character under cursor with character ch (no<Esc>) Replaces text from cursor to right Replaces single character under cursor with any number of characters Replaces entire line
From input mode ZZ From input mode to command mode press <Esc> and from command mode To Save :w To Quit :q To save & quit :wq or :x
Command O or l $ b e w
Function Moves cursor to beginning of line (no repeat factor with O) Moves cursor to end of line Moves cursor backwards to beginning of word Moves cursor forward to end of word Moves cursor forward to beginning of word
Paging Functions
Command <Control-f> <Control-b> <Control-d> <Control-u> <Control-l> Function Full page forward Full page backward Half page forward Half page backward Redraw page screen (no repeat factor)
Commands
fch
Functions
Moves cursor forward to first occurrence of character ch in the current line tch Moves cursor forward onto but before first occurrence of character ch in the current line ; Repeats search in the same direction along which the previous search was made with f or t , Repeats search in a direction opposite to that along which the previous search was made with f or t
Joining line J - to join current line with next line 4J - to join 4 lines from current line Marking Text m <single char label> - to mark line <single char label> - to locate marked line
Repeating last Instruction - . (dot key) Undo last Instruction - u Reverse all changes made to current line - U
d$ or D 5dd d/endif
d30G df. c0 c$ or C
Deletes from cursor to end of line Delete five lines Deletes from cursor up to the first occurrence of the string endif in the forward direction Deletes from cursor up to line number 30 Deletes from cursor to first occurrence of a dot Changes from cursor to beginning of line Changes from cursor to end of line
ex mode commands
Command :r note :w :w note1 :w! note1 Function Reads file note into present cursor location saves buffer and remains in editing mode Creates file note1 and writes buffer contents to it Overwrites contents of file note1 with contents of buffer Appends buffer contents to file note1
:w>> note1
ex mode commands
Command Function :x Saves buffer and quits editing mode :wq Saves buffer and quits editing mode :q Quits editing mode without saving :q! As above but after abandoning changes :e note1 Stops editing current file, and edits file note1 e! note1 As above, but after abandoning changes made to current file
ex mode commands
Command :e! :e # :n :rew Function Loads last saved edition of current file Returns to editing the most recently edited file Edits next file (on the vi command line) Rewinds file list to start editing from first file specified in the command line Cursor at start of 100th line
100
Abbreviation ai aw
Significance Next line starts at the previous indented level switching files with :n and escaping to the shell with :sh
ignorecase ic magic
Ignores case while searching for patterns Treats the characters of the regular expression set as special while searching for patterns
Option number
Abbreviation nu sm
Significance Displays line numbers on screen Shows momentarily the mach to a ) & } Displays a message when vi is in input mode
showmatch showmode
tabstop
wrapscan
ts
ws
Abbreviate
Options to vi
To salvage a file after crash $ vi -r <file> to begin from specified line $ vi +<line> <file> to begin with specified pattern $ vi +/<pattern> <file>
Searches for a given pattern in the files specified grep <options> <pattern> <filename(s)> Options -c displays count of occurrences -l displays list of filenames only -n displays line number along with lines -v displays all but the line matching pattern
Options ( cont..) --i ignores case -h omits filename -f fname reads expression/pattern from file (egrep & fgrep option) -x displays lines match in entirety (fgrep option)
grep Command
e.g.
$grep sales emp.lst - lists records with sales as dept $grep sales emp.lst $str = sales $grep -c $str emp?.lst will count no. of directors in all emp?.lst display will be for each file separate
Expression ch* [pqr] [^pqr] - 0 or more occurrence of char ch - matches single char p, q or r - matches single char which is not p, q or r [c1-c2] - match single char within ASCII range specified
Expression .(dot) -matches with any single character ^pattern - matches with pattern at beginning of pattern$ - matches with pattern at end of line ch \ {m\} - matches m occurrence of char ch ch \ {m,n\} - matches min. m & max. n occurrence of char ch ch \ {m,\} - matches min. m occurrence
line
egrep Command
egrep
- Extending grep
ch+
ch?
exp1/exp2 (x1/x2)x3 x1/x2
Matches or 1 char ch
matches exp1 or exp2 expression matches expression x1x3 or x2x3 matches expression x1 or x2
egrep Command
e.g.
fgrep Command
fgrep
e.g.
- multiple string searching only simple (pattern) string or group of strings can be searched faster than grep and egrep $fgrep -f pat.lst emp.lst $cat pat.lst sales admin
No options to identify & work with fields Output formatting, computations etc. Not possible Extremely difficult to specify patterns/ R.E always.
Report writer : very powerful text manipulation utility Named after Aho Weinberger Kernigham As powerful as any programming language It can access, transform and format individual fields in a record Generally awk programs are slow.
Line specifier and action option are optional, either of them needs to be specified line specifier not specified indicates all lines to be selected {action} omitted indicates print (default) fields are identified by special variable $1, $2, .; default delimiter is contiguous string of spaces
Explicit delimiter can be specified using -F option e.g. awk -F | /sales/,print $3, $4- emp.lst Regular expression of egrep can be used to specify pattern Line numbers can be selected using NR built-in variable $awk -F | NR ==3, NR ==6 ,print NR, $0- emp.lst
Output can be formatted using printf similar to printf in c but not a function e.g. $awk -F | /*aA+gg?*ar++wal/, >printf %3d%-20s%-12s%d\n, NR, $2,$3,$6- >emp.lst Record no./ Line number will be printed , (comma) to be used as delimiter in printf
$awk - F | $3 ==director || $3 == chairman, >printf %-20s,$2- emp.lst Relational Operators : <, <=, ==, !=, >=, >, ~, !~ e.g. $awk -F | $6>7500 ,printf %20s, $2- emp.lst e.g. $awk -F | $3 == director || $6>7500 , >print $0- emp.lst
== tries to find perfect match but string may have trailing spaces to overcome this ~ and !~ (match & negate of match) can be used with R.E. $awk -F | $2~/director/||$~/g.m/, >printf $0- emp.lst $3 ~/^g.m/
Number Processing
Computation on numbers can be done +, -, *, /, % operator available no type declaration for variables variables initialized to zero
awk Command
-f option awk program can be written in a separate file and used in awk e.g. $awk -F | -f emp.awk emp.lst single quoted contents are written in this file without quotes
awk Command
BEGIN and END Section Format: (i) BEGIN {action} (ii) END {action} awk<options> BEGIN ,actionline specifier {action} END ,action- <files>
awk Command
e.g.
$cat emp.awk BEGIN { printf \n\t Employee details \n\n } $6>7500{ # increment sr. no. and sum salary kount++; tot+=$6 printf %d%-20s%d\n, kount, $2, $6 } END { printf \n The Avg. Sal. Is %6d\n, tot/kount } $_ &awk -F | -f emp.awk emp.lst
awk Command
requires entire awk command should be in the shell script to differentiate positional parameter and field identifier, the positional parameter should be single quoted in awk program e.g. $3 > $1
nawk
Enhancements to awk available as new command - nawk. Its possible to use getline statement to accept I/p from the user or from a file. Its possible to use the built-in variables ARGC & ARGV to check arguments passed. Its possible to define own functions. Its possible to use the system function to run unix commands or any other executable within nawk. The ?: operator as in C is available within nawk. getline x < Emp.lst getline x < /dev/tty
Built-in Variable
NR - Cumulative no. of records read FS - The i/p field separator OFS - The output field separator NF - No. of fields in current record FILENAME- The current i/p file ARGC - No. of arguments in command ARGV - List of arguments
line
Built in functions
- Returns integer value of x - Returns square root of x - Returns the position of string s2 in - Returns length of the argument
s1
Built in functions
Functions substr(s1,s2,s3) - Returns portion of string of length s3,starting position s2 in string s1 split(s,a) - Split string s into array a optionally returns no. of fields
Arrays
Can handle single dimension array index can be anything even string no declaration required, initialized to zero automatically e.g. totl[1] +=$6; tot[2]+=da; tot[3]+=HRA; temp[$3]
Redirection > , piping | possible restriction - filenames, commands that follows these symbol must be in double quotes Programming constructs : (I) if then if (conditions is true) <statements> else <statements>
(iii)
(iv)
(v)
for loop for arrays for (k in array) <commands> While loop while (condition is true) { } break and continue
Shell Variables
System Variables
Set during
- login
- booting
Shell Variables
list of variable
PATH - list of dir. In order of precedence that have to be scanned for hunting command
Home - dir. Named after Login name
IFS - string of char which are used as word separator in the command line
MAIL - mail directory
Shell Variables
DATA in the same file - The here document < redirection symbol, redirects the standard input to come from a file << here document symbol signifies data is here rather than in a Separate file
Shell Variables
e.g. $grep director <<mark - delimiter to indicate end of document >1001 | Sanjay | g.m. | 5 >5001 | Rahul | director | 7 : : >mark
Read Statement
Takes input from standard i/p can be used to read one or more variables e.g.echo \n Enter the Pattern : \c read patname echo \n Enter file name : \c read fname grep $patname $fname
Shell procedures arguments in command Arguments are specified along with the name of shell procedure Arguments are assigned to special variables (positional parameters) $1 - First parameters $2 - Second parameters : :
Special parameters also available $0 - Name of executed command $* - Complete set of positional parameters $# - No. of arguments $$ - PID of current shell $! - PID of last background job $? - Exit status of last command $@ - Same as $* except when enclosed in double quotes
2 3 4
Conditional Execution
&& operator delimits two commands, the second command is executed only if first succeeds
|| operator delimits two commands, the second command is executed only if first fails $grep `director` emp.lst && echo patern found $grep `manager` emp.lst || echo pattern not found
e.g.
Conditional Execution
e.g.
if Statement
Format : (i) if <condition is true> then <execute commands> else (execute commands> fi (ii) if <condition is true> then <execute commands> fi
if Statement
(iii)
if <condition is true> then <execute commands> elif <condition is true> then <execute commands> <> <> else <execute commands> fi
if Statement
Condition can be specified either using test or [cond] Relational Operator used
eq
Equal to nc Not equal to gt Greater than gc Greater than or equal to lt Less than lc Less than or equal to
if Statement
Trace if <file> exists if exists & regular file if exists & readable if exists & writable if exists & executable if exists & is dir file if exists & size > 0
S1! = S2
str
True, if S1 S2
True, if str is assigned and not null
Logical Operators
a O !
.AND. .OR.
Not
e.g.
If test $x -eq $y
Format : case <expression> in <pattern 1> ) <execute commands> ;; <pattern 2> ) <execute commands> ;; <> <> esac
e.g.
echo \n Enter Option : \c read choice case $choice in 1) ls -l ;; 2) ps -f ;; 3) date ;; 4) who ;; 5) exit ;;
esac
While Statement
While Statement
e.g. while [$x -gt 3] do ps -f sleep 5 done while true do ps -f sleep 5 done
e.g.
While Statement
E.g. Script to edit, compile & execute a program while true do cc $1 case $? In o) echo Compilation Successful echo Executing a.out a.out ; exit ;; *) echo Compilation Error echo Press <Enter> to edit read pause vi $1 ;; esac done
Continue
following it, and switches control to top of loop for next iteration
Until Statement
Complement of while stm loop body is executed repeatedly as long as the condition remains false e.g. until false do ps -f sleep 5 done
for Statement
for Statement
e.g.
e.g.
e.g.
for x in 1 2 3 do echo The value of x is $x done for var in $PATH $HOME $MAIL do echo $var done for file in *.c do cc $file done
While Statement
E.g. Script to edit, compile & execute a program while true do cc $1 case $? In o) echo Compilation Successful echo Executing a.out a.out ; exit ;; *) echo Compilation Error echo Press <Enter> to edit read pause vi $1 ;; esac done
Continue
following it, and switches control to top of loop for next iteration
Until Statement
Complement of while stm loop body is executed repeatedly as long as the condition remains false e.g. until false do ps -f sleep 5 done
for Statement
for Statement
e.g.
e.g.
e.g.
for x in 1 2 3 do echo The value of x is $x done for var in $PATH $HOME $MAIL do echo $var done for file in *.c do cc $file done
Process
Instance of program in execution Many processes can run at the same time Every process identified by Process Identifier PID is allocated by kernel
On logging to system, a process is set up due to execution of shell Shell is the parent process for every other process setup due to execution of commands Every process has a parent process Parent process waits for death of child process before resuming execution.
Process Status
ps command to display characteristics of a process options -f - full form -u - details of only users processes -a - all processes details -l - detailed listing -e - system processes
Background Process
To run a process in background, use & operator $sort -0 emp.lst emp.lst &
nohup (no hangup) - permits execution of process even if user has logged off $nohup sort emp.lst & sends output to nohup.out
wait waits for child process to complete $wait 138 - waits for background job with pid 138 kill $kill 1005 (default signal 15) kills job with pid 1005 $kill -9 1005 sure killing of job $kill 0 - kills all background process
prefix the command with nice $nice wc -l xxx $nice -15 wc -l xxx
reduce priority by 15 units
News command invoked by user to read any message sent by administrator Messages stored in /usr/news options: -n,-s,-a
motd
write command: allows 2-way communication between users who are logged on. Message occurs on screen anytime it is sent. The mesg command with parameter n prevents disturbances.
mail command: single channel communication. User need not be logged on : message gets saved in users mailbox. Many internal commands available within mail.
wall command used by system administrator to send messages to all logged on users.
While Statement
E.g. Script to edit, compile & execute a program while true do cc $1 case $? In o) echo Compilation Successful echo Executing a.out a.out ; exit ;; *) echo Compilation Error echo Press <Enter> to edit read pause vi $1 ;; esac done
Continue
following it, and switches control to top of loop for next iteration
Until Statement
Complement of while stm loop body is executed repeatedly as long as the condition remains false e.g. until false do ps -f sleep 5 done
for Statement
for Statement
e.g.
e.g.
e.g.
for x in 1 2 3 do echo The value of x is $x done for var in $PATH $HOME $MAIL do echo $var done for file in *.c do cc $file done
Program Development
CC Make SCCS
CC Command
The UNIX system compiler for C. cc compiles the file if no errors are found an executable version of the file is created. The default name of the executable file is a.out Invokes a series of programs the preprocessor, the compiler and the linker. Subprograms can be compiled together.
Make Utility
Make utility and makefiles help automate building of an application. Modifying any one or more of the source files requires recompilation of that part of the program and relinking. Automate this process by specifying the interdependencies between files that make up the application along with the commands needed to recompile and relink each piece.
Make Utility
During program development a number of subroutines may be developed separately and linked at the end. However keeping a track of the updated versions is difficult. Further, files that are changed may not be recompiled.
Make Utility
These instructions are placed in make file. The command make is used to execute instructions defined in make file. $ make myprog
Make Utility
A make file consists of a series of entries of the following form: [.....dependencies....] [.....commands........]
Make Utility
main.o: main.c cc -c main.c Makefile and all files referenced by MAKE should be in the same directory. Sees the dependencies upon program.Then checks to see if program is current
SCCS is a group of programs that help in controlling the various versions of a program. Multiple copies are not stored. Only incremental changes to the program are stored.