UNIX - Introduction UNIX an Operating System Master Control Program UNIX a name of a culture UNIX a...

Preview:

Citation preview

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 costUniversities dissect UNIX and train new usersComputer Systems Research Group at Berkley:

Supported by DARPA, make significant changes to UNIX and distribute it as Berkley Software Distribution

1 BSD for PDP-112 BSD3 BSD4.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 SystemUNIX 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 ControlFE Format EffectorIS Information Separator

000 001 010 011 100 101 110 1110000 NUL DLE SP 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EOT DC4 $ 4 D T d t0101 ENQ NAK % 5 E U e u0110 ACK SYN & 6 F V f v0111 BEL ETB ' 7 G W g w1000 BS CAN ( 8 H X h x1001 HT EM ) 9 I Y I y1010 LF SUB * : J Z j z1011 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 CC1 ^A SOH Start Of Heading CC2 ^B STX Start Of Text CC3 ^C ETX End Of Text CC4 ^D EOT End Of Transmission CC5 ^E ENQ Enquiry CC6 ^F ACK Acknowledge CC7 ^G BEL Bell8 ^H BS Backspace FE9 ^I HT Horizontal Tab FE10 ^J LF Line Feed FE11 ^K VT Vertical Tab FE12 ^L FF Form Feed FE13 ^M CR Carriage Return FE14 ^N SO Shift Out graphic set 15 ^O SI Shift In graphic set

Number Keys Control Description Category

16 ^P DLE Data Link Escape CC17 ^Q DC1 Device Control 118 ^R DC2 Device Control 219 ^S DC3 Device Control 320 ^T DC4 Device Control 421 ^U NAK Negative Acknowledge CC22 ^V SYN Synchronize Idle CC23 ^W ETB End of Transmission Block CC24 ^X CAN Cancel25 ^Y EM End of Medium26 ^Z SUB Substitute27 ^[ ESC Escape28 ^\ FS File Separator IS29 ^] GS Group Separator IS30 ^^ RS Record Separator IS31 ^_ US Unit Separator IS127 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 isatest

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-rwxrwxrwxPosition 1 is file typePositions 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

Recommended