Professional Documents
Culture Documents
UNIX
Dr. Emmanuel Shubhakar Pilli
Graphic Era University
Unix History
q
7/30/2012
q
q
7/30/2012
7/30/2012
Unix Philosophy
Write programs that do one thing and do it well
q Write programs that work together, allowing the
output of one to become the input of another
q
7/30/2012
The Law
January, 1949 DOJ filed an antitrust complaint
against Western Electric and AT&T
q In January, 1956, a consent decree was entered
q
u
u
7/30/2012
no advertising
no support
no bug fixes
payment in advance
11
q
q
q
13
10
3
3
Austria
Belgium
Germany
Venezuela
United States
1
1
1
1
101
12
7/30/2012
Berkeley Unix
Robert Fabrey, of UC Berkeley, was on the SOSP
program when Thompson presented his paper
q Together with the Math department, he purchased
a PDP-11/45 and had Unix running by Jan 74
q By 78 Bill Joy had produced a Pascal compiler
and began producing the Berkeley Software
Distribution (BSD) for $50 containing:
q
u
u
13
14
7/30/2012
Dueling Unixes
Up until 78, Unix meant AT&Ts operating system
q After this, there were two principle flavors of Unix
q
u
u
BSD
System V
15
Portability
u
u
q
q
q
q
q
7/30/2012
Challenges of Unix
q
17
18
7/30/2012
19
Major Personalities
q
q
q
q
q
q
q
q
q
q
q
q
Ken Thompson
Dennis Ritchie
Joe Ossanna
Rudd Canaday
Robert Fabrey
Steve Johnson
Stephen Bourne
Doug McIlroy
Kirk McKusick
Armando Stettner
Heinz Lycklama
Bill Joy
q
q
q
q
q
q
q
q
q
q
q
q
Co-Inventor of Unix
Co-Inventor of Unix
Author of troff
Original file system collaborator
Obtained DARPA funding for BSD
Author of lint and yacc
Author of the Bourne shell, sh
Originator of pipe concept
Wrote Berkeley Fast File System
Got DEC to acknowledge Unix
Chaired first Unix standards group
Author of csh, ex, vi, termcap, and
much of BSD
20
10
7/30/2012
21
u
u
u
u
the hardware
the kernel, the hardware interface unique to a platform
the shell and other system utilities
the application programs
22
11
7/30/2012
23
So Why Unix?
q
24
12
7/30/2012
Unix Shells
A shell is the user interface or set of programs
user to interact with Unix and process commands
q Common shells are:
q
Bourne
u C
u Korn
u
25
26
13
7/30/2012
C Shell (csh)
Written by Bill Joy at University of California at
Berkeley
q Slower and more complex than Bourne shell, but
has facilities to make it more user friendly
q
alias
u history
u job control
u filename completion
u
27
28
14
7/30/2012
Superuser
q
29
Password Security
Unfortunately, password security is a necessity
q Good passwords have several characteristics
q
30
15
7/30/2012
To logout
u
u
clyde% exit
or clyde% logout
31
32
16
7/30/2012
exit or logout
q
34
17
7/30/2012
Process Concepts
q
q
q
q
q
Unix Processes
Every command executed on Unix is a process
q Unix processes are hierarchical
q
36
18
7/30/2012
Process Blocks
q
a process identifier
the process state
the value of the processs program counter
other information specific to the process such as
l memory limits
l files in use
l processor time used
l ....
37
Command Components
q
38
19
7/30/2012
Command Notation
command name
q [ ] optional arguments or options
q
can be nested
l [ arg1 [ arg2 ] ]
l [...]
| is an OR condition
u
arg1 | arg2
39
who
q
clyde% who
root
console
krf
ttyp0
Jul 22 09:36
Aug 7 10:32 (dal-tx2-33.ix.ne)
40
20
7/30/2012
CALendar - cal
q
clyde% cal
clyde% cal 9 1752
41
date
Display or set the date
q Syntax:date [-u] [-a [-] sss.fff] [yymmddhhmm [.ss]]
q
clyde% date
clyde% date -u
clyde% date +%T
42
21
7/30/2012
finger
Displays information about users
q Syntax: finger [options] user_name
q By default, finger displays user_names:
q
u
u
u
u
u
u
u
login name
full name
terminal name
idle time
login time
location
first line of .plan file
43
mail
Read or send electronic mail messages
q Syntax: mail [-deHinNUv] [-f [filename | +folder] ]
[-T file]
or: mail [-dFinUv] [-h number] [-r address] [-s
subject] recipient ...
q First form is for reading mail, second is for
sending mail
q For this class:
q
u
u
u
22
7/30/2012
clyde% man ps
clyde% man -k compile
clyde% man -f /var/spool/mail
clyde% man link
clyde% man 2 link
clyde% man 8 link
45
whois
q
Examples:
clyde% whois -h rs.internic.net Earthlink.com
clyde% whois -h rs.internic.net Krol, Ed*
46
23
7/30/2012
show ProcesSes - ps
Displays the status of current processes
q Syntax: ps [ [-] acCegjklnrSuUvwx] [-tx] | [num]
[kernel-name] [c-dump-file] [swap-file]
q Default is to display only processes with your
effective user ID
q We will only use the following options:
q
Example:
clyde% ps -a
47
talk Example
clyde% talk krf
Message from Talk_Daemon@clyde at 17:39 ...
talk: connection requested by krf@clyde.dcccd.edu.
talk: respond with: talk krf@clyde.dcccd.edu
Respond as shown and a split screen will be
displayed with your input in one half and your talkmates output in the other
q To end the session, type Control-c
q
48
24
7/30/2012
MESsaGe - mesg
Permit or deny messages on your terminal
q Syntax: mesg [n] [y]
q
u
u
u
49
clyde% pwd
/home/clyde/krf
clyde%
50
25
7/30/2012
u
u
51
mail(pine)
PINE 4.10
MAIN MENU
? HELP
C COMPOSE MESSAGE
MESSAGE CHECK
L FOLDER LIST
A ADDRESS BOOK
S SETUP
Q QUIT
? Help
P PrevCmd
R RelNotes
K KBlock
52
26
7/30/2012
File System
q
From the users view, files are data that you want,
directories are containers of files
q In reality, files are simply a stream of bytes
q
53
54
54
Tree Structure
27
7/30/2012
55
55
File Names
Every file has a filename
q Current versions of Unix allow up to 255
characters, older versions limit to 14
q Almost any character can be used in a filename
q
56
56
28
7/30/2012
57
57
u
u
u
user (u)
group (g)
other (o)
58
58
29
7/30/2012
System
u Work groups
u Individual users
u
59
59
ifs
Digital
Unix
ufs
NFS
nfs
nfs
nfs
nfs
NFS
nfs
nfs
nfs
CD
cdrfs
cdfs
cdfs
HS
hsfs
hsfs
iso
9660
iso
9660
ufs
swap
DOS
pcfs
dos
msdos
proc
proc
proc
s5
hfs
sysv
Swap
AIX
HP
Unix
hfs
SCO
Unix
EAFS
Sun
OS
4.2
Solaris
IRIX
Linux
ufs
efs
ext2
DOS
/proc
procfs
other
advfs
vxfs
S51K
lofs
minux
60
60
30
7/30/2012
61
61
ReMove file(s) - rm
Removes (deletes) files
q Syntax: rm [ - ] [ -fir] filename ...
q
u
u
u
u
62
62
31
7/30/2012
63
63
LiSt directory - ls
List the contents of a directory
q Syntax: ls [-aAcCdfFgilLqrRstu1] filename
q
u
u
u
u
u
u
64
64
32
7/30/2012
Change Directory - cd
Change current working directory
q Syntax: cd [directory]
q
u
u
65
65
Absolute Pathnames
Every file has a pathname
q A pathname is built by tracing a path from the root
directory, through all intermediate directories, to
the file
q String all the filenames in the path together,
separating them with slashes ( / ) and proceeding
them with the root directory ( / )
q Example: /usr/src/cmd/date.c
q
66
66
33
7/30/2012
Path Names
67
67
Relative Pathnames
q
. (this directory)
.. (the parent directory)
68
68
34
7/30/2012
inode
q
69
LiNk - ln
Create a pseudonym for an existing file
q Syntax: ln [-fs] filename [linkname]
q
u
u
70
70
35
7/30/2012
71
71
72
72
36
7/30/2012
touch
Update the access and modification times of a file
q Syntax: touch [-c] [-f] filename ...
q
u
u
73
73
74
74
37
7/30/2012
more
Page through a text file
q Syntax: more [-cdflsu] [-lines] [+linenumber]
[+/pattern] [filename...]
q
75
75
head
Display the first few lines of a specified file
q Syntax: head [-n] [filename...]
q
76
76
38
7/30/2012
tail
Displays the last part of a file
q Syntax: tail +|-number [lbc] [f] [filename]
or: tail +|-number [l] [rf] [filename]
q
Word Count - wc
Display a count of lines, words, and characters
q Syntax: wc [ -lwc ] [ filename ... ]
q
l - count lines
u w - count words
u c - count characters
u
Example:
clyde%wc testfile
7
43 168
testfile
clyde%
78
78
39
7/30/2012
Metacharacters
q
q
q
q
q
79
79
history
Display the history list in the C or Korn shells
q Syntax: history [ -hr ] [ n ]
q
u
u
80
40
7/30/2012
PaGe - pg
q
q
q
q
q
81
81
Searching with pg
q
q
q
q
82
82
41
7/30/2012
83
83
Forms of cp
q
84
42
7/30/2012
MoVe file - mv
Move or rename files
q Syntax: mv [ - ] [ -fi ] filename1 filename2
mv [ - ] [ -fi ] directory1 directory2
mv [ - ] [ -fi ] filename ... directory
q
85
85
cp Versus mv
mv simply changes the filename or absolute
pathname of the affected files, the files inodes
are not changed
q cp creates new files so new inodes are created,
unless the copy is overwriting an existing file
q
86
86
43
7/30/2012
87
87
lpr
lpr sends a job to the printer via the print spooler
q Syntax: lpr [-Pprinter] [-#copies] [-Ttitle] [-h]
filename
q
88
88
44
7/30/2012
u
u
u
-P
printer queue to display, default is
defined by environmental variable
PRINTER, or system default printer if
PRINTER isnt set
-l
display queue information in long format
+ interval displays the queue every interval
seconds until queue is empty
username displays jobs for username(s)
89
Example
lprm -Pps 144
removes job # 144 from ps queue
lrpm -Pversatec - removes all my pending jobs from
versatec queue
lprm 144
removes job # 144 from default
printer queue
90
90
45
7/30/2012
file
Attempts to determine the type of a file by
examining its contents
q Syntax: file [-ffile] [-L] filename
q
u
u
u
-ffile
get list of filenames to check from file
-L
if filename is a link, check the link
references rather than the link itself
filename... name of file(s) to check
91
91
u
u
u
-R
recursively descend through directory
arguments, changing the mode for each
mode
new value for file access permissions
mode, either octal or symbolic
filename filename(s) or directory(s) name to
modify
92
file
92
46
7/30/2012
Access Permissions
Each file and directory has a set of access
permissions associated with it
q You can see them by using the long form of ls
(ls -l)
q Format is srwxrwxrwx
q
u
u
u
u
93
Access Permissions
Only the owner (or superuser) can change the
access permissions of a file
q The execute bit must be set in order to cd into a
directory
q The shell variable umask sets the default access
permissions when you create a new file
q
94
94
47
7/30/2012
95
95
u
u
u
u
u
g
o
a
user
group
other
all
96
96
48
7/30/2012
97
97
49
7/30/2012
wait
What if you initiate several background processes
and then you decide that you need to wait until
they have all finished before doing something?
q wait will make the shell wait on all the background
processes to complete before giving you another
prompt
q
99
99
u
u
100
100
50