Unix Os Fundamentals
Unix Os Fundamentals
FUNDAMENTALS
STEVEN STEPANEK
CALIF STATE UNIV, NORTHRIDGE
COMPUTER SCIENCE DEPARTMENT
NORTHRIDGE, CA 91330
[email protected]
UNIX OPERATING SYSTEM Copyright © 2000 by Steven Stepanek
1
UNIX ® Operating System
Fundamentals
Introduction:
Functional properties of UNIX 5
UNIX philosophy 8
Origins of UNIX 10
Movement towards a standard 12
Relationship between C and UNIX 14
Shell Operations:
Command interpretation shells 16
Command line structure 18
Correcting typing errors 20
Some useful utilities 21
Shell input/output redirection 27
Pipes and filters 29
Extended I/O redirection in the Bourne shell 32
Foreground / background 33
Text Processing:
Common editors 59
Regular expressions 64
PROVIDE:
• MULTI-TASKING SUPPORT
SMALL
MODULAR
FLEXIBLE
EDITORS C BOURNE
SHELL SHELL E-MAIL
UNIX
KERNEL
HARD-
WARE
WORK DBMS
BENCHES SYSTEM
COMPILERS
UTILITIES
APPLICATION
PACKAGES
1980's
AT&T UC BERKELEY
SYSTEM III 2.8, 2.9, 2.10
SYSTEM V 4.1, 4.2, 4.3, 4.4
V8, V9 ,V10
ORGANIZATIONS INVOLVED:
IEEE UniForum
X/OPEN OSF
ISO others . . .
1003.0 GUIDE
1003.1 SYSTEM SERVICES, C BINDINGS
1003.2 SHELLS AND TOOLS
1003.3 COMPLIANCE TESTS
1003.4 REALTIME EXTENSIONS
1003.5 ADA LANG BINDINGS
1003.6 SECURITY
1003.7 SYSTEM ADMINISTRATION
1003.8 NETWORK FILE ACCESS
1003.9 FORTRAN LANG BINDINGS
1003.10 SUPERCOMPUTING
1003.11 TRANSACTION PROCESSING
1003.12 PROTOCOL INDEPENDENT IPC
1003.13 REALTIME APPLICATION ENVIR
1003.14 MULTIPROCESSING
1003.15 BATCH SERVICES
UNIX OPERATING SYSTEM Copyright © 2000 by Steven Stepanek
13
RELATIONSHIP BETWEEN C AND UNIX
SHELL PROMPTS:
% C SHELL
STANDARD
sh BOURNE
SHELL
BERKELEY
C csh
SHELL
SYSTEM V
sh or
BOURNE
sh5
SHELL
KORN
ksh SHELL
SIMPLE COMMAND:
cmd parameter . . .
$ sort -r report
$ cal 2 2001
February 2001
S M Tu W Th F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28
February 2002
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
• FILE LISTING
cat [file] . . .
more [file] . . . (BSD)
pg [file] . . . (SVID)
• FILE COPY
cp old new
• FILE RENAME
mv old new
rm file . . .
lpr [file] . . .
print [file] . . .
• DIRECTORY LISTING
ls
• MAIL A MESSAGE
mail [acctname] . . .
who
date
• CHANGE PASSWORD
passwd
stty [arg] . . .
$ stty
speed 1200 baud; evenp
intr = ^c; erase = ^?; kill = ^u;
brkint echo
$ stty
speed 1200 baud; evenp
intr = ^c; erase = ^h; kill = ^u;
brkint tab3 echo
SECTIONS:
1. COMMANDS
2. SYSTEM FUNCTIONS
3. LIBRARY FUNCTIONS
4. FILE FORMATS (BSD 5)
5. MACROS (BSD 7)
6. GAMES
7. SPECIAL FILES (BSD 4)
8. MAINTENANCE
SYNTAX
passwd [ name ]
DESCRIPTION
The passwd command changes or installs a password associated with the
user name (your own name by default).
The program prompts for the old password and then for the new one. The
caller must supply both. The new password must be typed twice, to
forestall mistakes.
Only the owner of the name or the superuser may change a password; the
owner must prove he knows the old password.
RESTRICTION
The passwd command will not change your password if your login entry is
served by the yellow pages (YP) since the /etc/passwd file is referenced
and not the yp map. Refer to yppasswd(1yp) for more information.
FILES
/etc/passwd
SEE ALSO
login(1), yppasswd(1yp), crypt(3), passwd(4yp)
cat try it
stdout
SCREEN
cat try it
SCREEN
stderr
WITHOUT PIPES:
$ who
sgs tty02 Feb 7 09:15
cxb tty04 Feb 7 08:59
$ who > temp
$ sort temp
cxb tty04 Feb 7 08:59
sgs tty02 Feb 7 09:15
$ rm temp
$ who | sort
cxb tty04 Feb 7 08:59
sgs tty02 Feb 7 09:15
$ ls | sort -r | more
BOURNE SHELL:
% kill %1
HIERARCHICAL:
(acct log on directory)
DIGITS
UNDERSCORE
PERIOD
COMMA
.c C SOURCE
.f FORTRAN 77 SOURCE
.p PASCAL SOURCE
.s ASSEMBLY SOURCE
.h C HEADER FILE
.o UNLINKED OBJECT
ls -a
. .login
. . .cshrc
.profile .logout
-, f PLAIN
b BLOCK DEVICE
c CHARACTER DEVICE
d DIRECTORY
l SYMBOLIC LINK
p NAMED PIPE
s SOCKET
$ ls -a
. .. .profile abm bam bat
battle project
$ echo ???
abm bam bat
$ echo ?a?
bam bat
$ echo ?a*
bam bat battle
$
$ ls -a
. .. .profile abm bam bat
battle project
$ echo [ab]*
abm bam bat battle
$ ls -l [ab]m
ls: "[ab]m": No such file or directory
$ csh
% ls -l [ab]m
No match.
%
$ echo [ab][ab]m
abm bam
$ echo [a-zA-Z]*
abm bam bat battle project
UNIX OPERATING SYSTEM Copyright © 2000 by Steven Stepanek
44
FILE PATHS
(root)
/bin/ls
/usr/users/sgs/proj3/src
• RELATIVE PATHS
proj3/src
. . /cxb
. . / . . /tmp
. /proj3
• MAKE DIRECTORY
mkdir directory . . .
• REMOVE DIRECTORY
rmdir directory . . .
cd [directory]
pwd
• DIRECTORY LISTING
ls [-adgilR] [file] . . .
proj:
total 1
-rw-rw---- 1 sgs 58 Aug 24 12:53 it
• REMOVE
rm [-ir] file . . .
• COPY
cp file1 file2
cp file . . . directory
• MOVE
mv file1 file2
mv file . . . directory
$ ls -Rl
total 2
-rw-rw---- 1 sgs 15 Aug 24 12:52 old
drwxrwx--- 2 sgs 48 Aug 24 12:53 proj
proj:
total 1
-rw-rw---- 1 sgs 58 Aug 24 12:53 it
$ ln old proj/data
proj:
total 2
-rw-rw---- 2 sgs 15 Aug 24 12:52 data
-rw-rw---- 1 sgs 58 Aug 24 12:53 it
$ ls -iRl
total 2
754 -rw-rw---- 2 sgs 15 Aug 24 12:52 old
7021 drwxrwx--- 2 sgs 64 Aug 24 12:56 proj
proj:
total 2
754 -rw-rw---- 2 sgs 15 Aug 24 12:52 data
7020 -rw-rw---- 1 sgs 58 Aug 24 12:53 it
$ rm proj/data
proj:
total 2
7019 lrwxrwx--- 1 sgs 23 Aug 24 12:59 data ->
/usr/users/sgs/temp/old
7020 -rw-rw---- 1 sgs 58 Aug 24 12:53 it
$ rm proj/data
u + r
g - w
o = x
a u
g
o
UNIX OPERATING SYSTEM Copyright © 2000 by Steven Stepanek
56
$ ls -l
total 2
-rw-rw---- 1 sgs 15 Aug 24 12:52 old
drwxrwx--- 2 sgs 64 Aug 24 13:00 proj
$ chmod o+r old
$ ls -l
total 2
-rw-rw-r-- 1 sgs 15 Aug 24 12:52 old
drwxrwx--- 2 sgs 64 Aug 24 13:00 proj
$ chmod g-w old
$ ls -l
total 2
-rw-r--r-- 1 sgs 15 Aug 24 12:52 old
drwxrwx--- 2 sgs 64 Aug 24 13:00 proj
$ chmod g-w,o=rx proj
$ ls -l
total 2
-rw-r--r-- 1 sgs 15 Aug 24 12:52 old
drwxr-xr-x 2 sgs 64 Aug 24 13:00 proj
umask [modemask]
- - - | - w - | r w x
user group other
0 0 0 0 1 0 1 1 1
umask 027
UNIX OPERATING SYSTEM Copyright © 2000 by Steven Stepanek
58
COMMON EDITORS
ed file
vi file
Save file (does not cause exit from ed) 1,$w [file ]
Normal exit after save q
Abort exit (must issue command twice) q
Join range of lines together .,.+1j
Read (insert) contents of another file $r [file ]
Print line number after going to address $=
Print range of lines .,.p
STRING SEARCHING
COMMAND MODE
r 1 | r 2 MATCH r 1 OR r 2
(r ) NESTED EXPRESSION r