Vous êtes sur la page 1sur 35

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-PCs

UNIX for a wide range of hardware from PCs 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 60s.
Cooperative effort by GE, Honeywell, NCR, Bell Labs and universities
UNICS
Uniplexed Information and Computing Services
Ken Thompson, Bell Labs (Late 60s)
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

b
6
b
5
b
4
b
3
b
2
b
1
b
0

b
6
b
5
= 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
000 001 010 011 100 101 110 111
0000 NUL DLE SP 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EOT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y I y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SOH RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Most significant bits (6, 5, 4 ) Least
significant
ASCII character matrix
Number Keys Control Description Category
0 ^@ NUL CC
1 ^A SOH Start Of Heading CC
2 ^B STX Start Of Text CC
3 ^C ETX End Of Text CC
4 ^D EOT End Of Transmission CC
5 ^E ENQ Enquiry CC
6 ^F ACK Acknowledge CC
7 ^G BEL Bell
8 ^H BS Backspace FE
9 ^I HT Horizontal Tab FE
10 ^J LF Line Feed FE
11 ^K VT Vertical Tab FE
12 ^L FF Form Feed FE
13 ^M CR Carriage Return FE
14 ^N SO Shift Out graphic set
15 ^O SI Shift In graphic set
Number Keys Control Description Category
16 ^P DLE Data Link Escape CC
17 ^Q DC1 Device Control 1
18 ^R DC2 Device Control 2
19 ^S DC3 Device Control 3
20 ^T DC4 Device Control 4
21 ^U NAK Negative Acknowledge CC
22 ^V SYN Synchronize Idle CC
23 ^W ETB End of Transmission Block CC
24 ^X CAN Cancel
25 ^Y EM End of Medium
26 ^Z SUB Substitute
27 ^[ ESC Escape
28 ^\ FS File Separator IS
29 ^] GS Group Separator IS
30 ^^ RS Record Separator IS
31 ^_ US Unit Separator IS
127 DEL Delete
Control Codes Used by UNIX
Unix Code Usual Key Purpose
intr ^C Stop running program
eof ^D no more data
erase ^H erase last character
werase ^W erase last word
kill ^U erase entire line
stop ^S stop output to screen
start ^Q 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 Standard input (default keyboard)
stdout Standard output (default screen)
stderr 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 copy standard input to output
colrm remove specific columns
crypt encode or decode with a key
cut extract selected columns or fields
fmt format to fit 72 characters per line
grep extract lines with a specific pattern
head extract first few lines of a file
Useful filters continued
less display file similar to more
more display file
nl create line numbers
paste combine columns of data
pg display file similar to more
rev reverse order of characters
sort sort or merge data
spell check spelling of words
Useful filters continued
tail extract lines at end of file
tr translate selected characters
uniq look for repeated lines
wc count number of lines, words or
characters

tee 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

Vous aimerez peut-être aussi