UNIX - Introduction

UNIX - Introduction
UNIX an Operating System
Master Control Program
UNIX a name of a culture
UNIX a set of tools for smart people
UNIX easy to use, difficult to learn
Other Operating Systems
•
•
•
MVS for IBM mainframes
VMS for Digital mainframes
DOS or Windows for IBM-PC’s
•
UNIX for a wide range of hardware from PC’s to mainframes
–
–
–
–
–
–
–
–
AIX from IBM
HP-UX from HP
SUNOS, SOLARIS from Sun
ULTRIX from Digital
A/UX from Apple
Minix from Tanenbaum,
LINUX
POSIX from IEEE Standard Group 1003
History of UNIX
• MULTICS
– Multiplexed Information and Computing Services
• Operating system for a GE 645 to serve all of Boston in mid 60’s.
Cooperative effort by GE, Honeywell, NCR, Bell Labs and universities
• UNICS
– Uniplexed Information and Computing Services
•
•
•
•
•
•
Ken Thompson, Bell Labs (Late 60’s)
Personal effort for a PDP-7 (64 KB), later for a PDP-11
Uses language B, which was derived from BCPL by Martin Richards
In 1973 Ken Thomson and Dennis Ritchie develop typed language C
The C Programming Language, Reference Manual 1978
ANSI C, starting 1983
UNIX
Name copyright of AT&T.
UNIX sold to universities at minimal cost
Universities dissect UNIX and train new users
Computer Systems Research Group at Berkley:
Supported by DARPA, make significant changes to UNIX and distribute
it as Berkley Software Distribution
1 BSD
for PDP-11
2 BSD
3 BSD
4.1 to 4.4 BSD
provides support for virtual memory,
networking, TCP/IP
Most popular version 4.32 BSD.
Computer System Research Group dissolved in 1993, due to cut in
funding.
Versions of UNIX after AT&T was broken up and allowed to sell software:
UNIX System III
Multiuser (not successful)
UNIX System V
developed with Sun Micro System
UNIX System V, Release 4
SVR4 and 4.3 BSD not compatible
AT&T issues SVID (System V Interface Definition) to keep vendors in
line, BSD camp ignores it.
Recent history
• UNIX System Laboratories (USL) set up by AT&T
• IEEE Standard Board tries to mend rift between SVR4 and
4.3 BSD by creating POSIX (Portable Operating System)
• New rift between AT&T and IBM
– IBM, DEC, HP and others set up Open Software Foundation
– Accept IEEE standards, but add additional ones for
• Windowing systems, X11 from MIT
• Graphical interface, Motiv
• Distributed computing etc.
• 1993 AT&T sells USL to NOVELL
• 1995 UNIX sold to Santa Cruz Operations Inc. and HP
The keyboard and ASCII
b6b5b4b3b2b1b0
b6b5 = 00 control code
= 01 special character or digit
= 10 upper case
= 11 lower case
Control Codes: CC Communication Control
FE Format Effector
IS Information Separator
ASCII character matrix
Least
significant
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
000
NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
HT
LF
VT
FF
CR
SOH
SI
001
DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US
Most significant bits (6, 5, 4 )
010
011
100
101
SP
0
@
P
!
1
A
Q
"
2
B
R
#
3
C
S
$
4
D
T
%
5
E
U
&
6
F
V
'
7
G
W
(
8
H
X
)
9
I
Y
*
:
J
Z
+
;
K
[
,
<
L
\
=
M
]
.
>
N
^
/
?
O
_
110
`
a
b
c
d
e
f
g
h
I
j
k
l
m
n
o
111
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
DEL
Number
Keys
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
^@
^A
^B
^C
^D
^E
^F
^G
^H
^I
^J
^K
^L
^M
^N
^O
Control
NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
HT
LF
VT
FF
CR
SO
SI
Description
Start Of Heading
Start Of Text
End Of Text
End Of Transmission
Enquiry
Acknowledge
Bell
Backspace
Horizontal Tab
Line Feed
Vertical Tab
Form Feed
Carriage Return
Shift Out graphic set
Shift In graphic set
Category
CC
CC
CC
CC
CC
CC
CC
FE
FE
FE
FE
FE
FE
Number Keys Control
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
127
^P
^Q
^R
^S
^T
^U
^V
^W
^X
^Y
^Z
^[
^\
^]
^^
^_
DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US
DEL
Description
Data Link Escape
Device Control 1
Device Control 2
Device Control 3
Device Control 4
Negative Acknowledge
Synchronize Idle
End of Transmission Block
Cancel
End of Medium
Substitute
Escape
File Separator
Group Separator
Record Separator
Unit Separator
Delete
Category
CC
CC
CC
CC
IS
IS
IS
IS
Control Codes Used by UNIX
•
•
•
•
•
•
•
•
Unix Code
intr
eof
erase
werase
kill
stop
start
Usual Key
^C
^D
^H
^W
^U
^S
^Q
Purpose
Stop running program
no more data
erase last character
erase last word
erase entire line
stop output to screen
start output to screen
Setting of keys
• stty –a
gives listing of key settings
• stty erase ^H either hold down control key
or type 2 characters: ^ and H
• stty kill k
will kill input line on typing k
not a good idea!
• stty intr ^? Interrupt assigned to escape key
Carriage return ^M and linefeed ^J
• UNIX stores single linefeed ^J in file to
indicate end of line
• DOS stores carriage return and linefeed
^M^J in file to indicate end of line
• Return key generates ^M
Example of UNIX and DOS files
This
is
a
test
Internal representation
• In UNIX 15 bytes
– 54 68 69 73 0A 69 73 0A 61 0A 54 65 73 74 0A
• In DOS 19 bytes
– 54 68 69 73 0D 0A 69 73 0D 0A 61 0D 0A 54 65 73
74 0D 0A
DOS file in a UNIX editor
This^M
is^M
a^M
Test^M
UNIX file displayed under DOS
This
is
a
Test
Translation on Input and Output
• UNIX wants to treat input from terminal and from
a file the same
• When file was created ^M was translated into ^J
• On output UNIX translates ^J into ^M^J
Entering Commands
• % who am I <cr>
– <cr> Return, Enter or ^M
– Until <cr> is pressed command can be edited
with ^H, ^W, ^U
– When UNIX receives ^M it translates it into ^J
and UNIX starts executing command
– Input is echoed to screen with ^J translated to
^M^J
Login and Logout commands
• login userid - initiates new login
• ^D – logs out when given a command to
login shell
• logout
• passwd – changes your password
File-Related Commands
•
•
•
•
•
•
•
cat file …
cp file1 file3
cp file … dir
more file
mv file1 file2
mv file … dir
rm file
Directory-Related Commands
•
•
•
•
•
cd dir
pwd
mkdir dir
rmdir dir
ls op [file … ]
Informational Commands
•
•
•
•
•
•
date
finger name
look prefix
man cmd
who
w
Permission settings - chmod
-rwxrwxrwx
Position 1 is file type
Positions 2,3,4 are permissions of u (user)
Positions 5,6,7 are permissions of g (group)
Positions 8,9,10 are permissions of o (other)
% ls –l hmk
-rwx--x--x 1 bermanka faculty 129 Jul 24 14:11 hmk
% chmod a+r hmk
% ls -l hmk
-rwxr-xr-x 1 bermanka faculty 129 Jul 24 14:11 hmk
Standard Files
• stdin
• stdout
• stderr
Standard input (default keyboard)
Standard output (default screen)
Standard error messages (screen)
Definition of Filter
• A program or command is called a filter if it
uses standard input and standard output.
• Most trivial example: cat sends stdin to
stdout
• Other examples: cut, less, more,…
• Not a filter: ls, w, who, …
Redirection of Input and Output
• < filename
take standard input from that file
• > filename
send standard output to filename
• Examples:
– ls > myfiles
– more < myfiles
– cat < myfiles >myfilestoo
Redirection of stdout can destroy existing files!
Use set noclobber to prevent accidental overwriting
If you want to overwrite an existing file
ls >! names
>> will append to an existing file
Redirection of stdin
• sort < file1 same as
sort file1
but sort file1 file2 has a different meaning it
will merge the files.
mail alex < memo
Will send file memo to user alex
List of useful filters
•
•
•
•
•
•
•
cat
colrm
crypt
cut
fmt
grep
head
copy standard input to output
remove specific columns
encode or decode with a key
extract selected columns or fields
format to fit 72 characters per line
extract lines with a specific pattern
extract first few lines of a file
Useful filters continued
•
•
•
•
•
•
•
•
less
more
nl
paste
pg
rev
sort
spell
display file – similar to more
display file
create line numbers
combine columns of data
display file – similar to more
reverse order of characters
sort or merge data
check spelling of words
Useful filters continued
•
•
•
•
tail
tr
uniq
wc
• tee
extract lines at end of file
translate selected characters
look for repeated lines
count number of lines, words or
characters
duplicates standard input
The UNIX pipe
• ls | more
• Same as
ls > temp
more < temp
rm temp
Using the tee utility
% who | tee who.txt | grep berman
Shell scripts
• File containing sequence of UNIX commands
• Created in vi or emacs:
#!/bin/csh
echo My name is Kenneth Berman
echo My user name is $user