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

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

  • View
    239

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 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

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

Page 2: 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

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

Page 3: 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

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

Page 4: 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

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

Page 5: 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

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.

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

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

Page 10: 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

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

Page 11: 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

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

Page 12: 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

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

Page 13: 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

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

Page 14: 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

Example of UNIX and DOS files

This isatest

Page 15: 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

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

Page 16: 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

DOS file in a UNIX editor

This^M

is^M

a^M

Test^M

Page 17: 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

UNIX file displayed under DOS

This

is

a

Test

Page 18: 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

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

Page 19: 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

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

Page 20: 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

Login and Logout commands

• login userid - initiates new login

• ^D – logs out when given a command to

login shell

• logout

• passwd – changes your password

Page 21: 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

File-Related Commands

• cat file …

• cp file1 file3

• cp file … dir

• more file

• mv file1 file2

• mv file … dir

• rm file

Page 22: 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

Directory-Related Commands

• cd dir

• pwd

• mkdir dir

• rmdir dir

• ls op [file … ]

Page 23: 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

Informational Commands

• date

• finger name

• look prefix

• man cmd

• who

• w

Page 24: 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

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

Page 25: 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

Standard Files

• stdin Standard input (default keyboard)

• stdout Standard output (default screen)

• stderr Standard error messages (screen)

Page 26: 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

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, …

Page 27: 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

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

Page 28: 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

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

Page 29: 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

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

Page 30: 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

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

Page 31: 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

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

Page 32: 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

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

Page 33: 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

The UNIX pipe

• ls | more

• Same as

ls > temp

more < temp

rm temp

Page 34: 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

Using the tee utility

% who | tee who.txt | grep berman

Page 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

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