<<

An Introduction to

Andrew Hazel

Department of Mathematics, University of Manchester

An Introduction to UNIX – p.1/29 .2/29 p – UNIX to Introduction An 1 1 control concepts Session Session job Session shells basic and and and Practical Lunch Practical Lunch Lecture 2: 2: 1: 1: Lecture Practical Lecture machines st Group Group Fir Group Group Second Final Final Break filesystem Introduction remote al UNIX course

of Gener The Using • • • 11:00–12:00: 12:00–13:00: 13:00–14:00: 14:00–14:45: 14:45–15:00: 15:00–15:30: 15:30–16:30: • • • • • • •

Outline .3/29 p – UNIX to vides Introduction UNIX An pro un it r vices ser computers the of erful y system po man ating and net oper and er inter v computing the ulti-user big fileser m

? pins or f tmental under

UNIX

is Multi-tasking, “Standard” UNIX Depar • • • •

What .3/29 p – UNIX to vides Introduction UNIX An pro un it r vices ser computers the of erful y w system po man ating and most vironment net oper en and er inter v computing the ulti-user amming r big fileser m

? pins or f ulti-tasking prog le le m tab xib tmental under ue or r UNIX antages T Fle P “Nice”

is • • • • Multi-tasking, “Standard” UNIX Depar Adv • • • • •

What .3/29 p – UNIX to vides Introduction UNIX An pro un it r vices ld or ser w computers the of erful y w system microsoft po man the ating and most vironment with net oper en and le e v er inter v cur iendly computing fr the ulti-user amming r big compatib fileser ning m

? user pins or f ulti-tasking prog le lear le m that 100% tab antages xib tmental under ue or r UNIX antages T Fle P “Nice” Not Steep Not

is • • • • • • • Multi-tasking, “Standard” UNIX Depar Adv Disadv • • • • • •

What .4/29 p – UNIX to Introduction An

?

you

for

do amming r eb E- W kages ε Prog 2 TRAN pac X uplot Wide

UNIX tmental E T Processing A ld FOR C/C++ Matlab Maple L Gn tecplot xt or • • • • • • •

can e Depar W Scientific T Plotting • • • • •

What .5/29 p – UNIX to erent Introduction An of ation r commands umber of n integ a handful master complete to small not a style ... need together on e than ou once y ams r viv them tant ely k sur or prog w ectiv file y impor couple a eff can people is and UNIX is most specialised users ams ything r y er ut use b w philosoph er o o Small Ev P Man T ... prog • • • • • •

UNIX .6/29 p – UNIX to y b Introduction An preted inter [files] and line vironment en m: xpression] or king f [e ] or ic command w yptic the our gener cr y options [ on the ect junk.txt e often aff *.c tak -l are entered -l can emacs lpq command are of commands messages shell commands UNIX Error Commands Choice the • • • •

UNIX .7/29 p – UNIX to Introduction An these use le) commands documentation to or f w ailab documentation v a ho or f online out search or f books to find pages to rooms eb used o w ux/unix inf be [email protected] lin commands o ords o of can inf yw inf tmental computer e k suppor (lots and the and to depar ! with in man man the books or e-mail at at -k the others

man y r Use man T Ask Look Look Send commands associated • • • • • • •

Getting .8/29 p – UNIX to as our y Introduction An same accessed sure obtain be the to e T computer can NO on order hostname that mak are in @ k ord. users w PC so circulate ac.u name account een pass to ersity ! user ord, betw w and m it univ e-mail xt or a f te pass mation, on name used the ersity use and or of user univ is be sending inf a register of name e can v y to a will ha tmental w user address tant ou a need

(E-)mail y is Depar ersity should will e-mail https://webmail.manchster. ou ou our at systems that E-mail An Y Y E-mail impor Univ y • • • • •

Electronic .9/29 p – UNIX to Introduction to to An is used UNIX are under editor (Esc) le y e files k an ailab initially v n a n editing Escape lear lear to editors the commands spent xt to te and be y of easiest actice editing a will the w (CTL) y of umber e n k so a one our y only specialised it, is are of control files use Most There emacs The The access • • • • •

Editing .10/29 p – UNIX to Introduction An queue s ’ m inter lpr pr and inter inter pr pr from lpq n or , f inter lpr pr are umber queue n the int to job pr es file v the commands Remo Lists Sends inting n pr file inter inter basic pr inter pr -P pr -P -l The -P m • lpr lpq lpr

Printing .10/29 p – UNIX it to send Introduction An being and gv queue ore ipt command s ’ the bef m tment] inter inter lpr ipt postscr pr pr using depar to and inter inter the ostscr pr pr the from P .txt lpq n in or , f k file using or into inter lpr onscreen y w pr file b ted are umber xt queue w only n the er te v inter vie int will to job pr pr the con pre t and es file v er the be ault be v commands y def ust con inter Remo Lists Sends ma m command pr our inter inting y will n pr files pr files ault file set .txt custom ipt the inter def ally a inter file to basic is can pr inter pr the -P pr -P ostscr ou -l to The Y [This Gener a2ps P command sent -P m • • • • • lpr lpq lpr

Printing .11/29 p – UNIX to the (or Introduction ies An ou y w y deletes director sho y mdir r will een director y) ies and / betw director e of v ies current y ) director director mo home our to y the to king director y to of or / w special w used y o subdirector ne is int a root tw director pr changes y) es) is (the itself the y has y director (or y y mak ies home from director (or our director director parent ucture y director arguments director lost path str to

filesystem the no the root e other subdirector change es) creates get is ers is v y y . .. the (or with ou ref er er y • • is ree-lik complete T / Ev Ev If cd ˜ remo UNIX • • • • • • • • •

The .12/29 p – UNIX to Introduction An dir y dir director y the dir/file1 into director be the files will file2 into to ultiple file1 file1 m

files path-name Its copies copies copies

ving dir mo &c

and file2 dir file2 file1 file1 file1 ying cp cp

Cop .12/29 p – UNIX to file Introduction An dir dir xisting y e y an dir dir director y director y iting the the erwr dir/file1 wfile dir/file1 v into director into director o ne be be the to files the files ore will will file2 into bef into to oldfile ultiple ultiple ou file1 m file1 file1 m y es es n v v path-name

files path-name Its mo renames mo w Its copies copies copies

ving will dir dir -i mo &c &c wfile ne and dir file2 file2 dir file2 and oldfile file1 file1 file1 file1 file1 ying -i cp cp cp mv mv mv cp

Cop .13/29 p – UNIX to Introduction An dir y files -r director m the deleting r in files file1 ore files file bef ultiple all the m ou using y es v ns ar remo deletes w deletes &c careful y

files file2 er dir file1 v -i -r file1 file1 m m m m r r r r Be

Deleting .14/29 p – UNIX to Introduction An y director iod) per a current with the in time ting files ies ies star the of creation director (those of director of and listing files order files in long a the contents files hidden files es lists lists lists giv list -l -a -t -R ls ls ls ls ls

Examining .15/29 p – UNIX file1 dir1/ Name to Introduction An 17:58 17:59 12 12 Sep Sep Timestamp e siz 0 1024 users users Group w w missions: andre per andre Owner file 1 2 the ws sho -l ls missions permissions er • P -rw-r–r– drwxr-xr-x

File .15/29 p – UNIX file1 dir1/ Name to Introduction An 17:58 17:59 12 12 y Sep Sep Timestamp director e or f siz d . 0 1024 File i.e users users Group file is w w missions: andre per andre Owner missions file per 1 2 Link the in y ws entr sho -l ls First missions permissions er • • P -rw-r–r– drwxr-xr-x

File .15/29 p – UNIX file1 dir1/ Name to Introduction An 17:58 17:59 12 12 y Sep Sep Timestamp director e or three f siz d of . 0 1024 File i.e roups g type users users Group file three is in w w missions: are mission andre per andre Owner mission missions missions per mission missions missions file per per per per per per 1 2 Link missions the in ite ecute y x wr per e ws read User Group Other is is is entr , , , sho u g o r w x -l • • • • • • ls First Access missions permissions er • • • P -rw-r–r– drwxr-xr-x

File .16/29 p – UNIX to Introduction An codes file file –x r– r– symbolic r– or missions rwx r– - - per file umbers pages n o missions inf missions using per per changes the the on the file es es changed ound giv giv f be file be file n1n2n3 y can 741 a=r

permissions ma file chmod chmod details missions er .g. .g. P e e Full • • • •

Changing .17/29 p – UNIX to ou y ite wr Introduction An to with ypchsh commands easier the language the lot Use a mechanisms system e y lif e amming ating shell. anslates r histor It mak shell. oper prog ault) . and a can ault (def it main as preter def tcsh the that our inter used to y is the completion be er v shell shells also co a uctions change command to of filename to can a , instr erent ne ipts is n diff going scr or into shell y antage Bour C K shell • • • • wildcards type A Adv The Man Only command shell • • • • •

Shells .18/29 p – UNIX to .g. e e lif Introduction e An .txt in mak .txt to ending used and be ing a str can y with another_long_file an than .txt ting in star ing.txt, acters replaces files ending char all which files * wfully_bor a is all files special xt, deletes all .te are lists used w lists a*.txt * *.txt m most ls ls r andre • • • easier Wildcards The • • ildcards

W .18/29 p – UNIX to .g. e e not lif Introduction e An .txt in mak ac.txt, .txt to or ending .txt used ab and be m ing a or f str can y with the another_long_file an than of .txt ting acter in files star ing.txt, char acters replaces files ending char delete all single which a files * wfully_bor only a is all files special only xt, will deletes all .txt .te are lists used w w lists a*.txt a?.txt * *.txt replace m m most ls ls r r andre andre will • • • • easier Wildcards The ? • • • ildcards

W .18/29 p – UNIX to y .g. in e an e lif e Introduction e v .txt or An .txt sant in in mak A-Z ver remo .txt to end will con a-z, ending and be used b 0-9, to and be or ing a [a-z].txt are a str m can r y es with with another_long_file an symbols) .g. t happen than e .txt rang ting etc ou star in y le star ASCII ing.txt, ange r acters that replaces c.txt, of alues a v files sensib ending char of files .txt, der (unless all y b which or list files * wfully_bor onl a denotes is all files a.txt, choice special will xt, the thereof deletes a all .te are lists used files w yphen umerical h n lists a*.txt the * *.txt [ab]*.txt arning m most the ls ls r ls The W subsets andre of encloses ] • • • • • • [ easier Wildcards The • • • ildcards

W .18/29 p – UNIX to .g. e e lif logical Introduction e An .txt a in as mak .txt to acts ending used ets k . e and be ac ing a br str with can y t with another_long_file an star than square .txt ting in in star ing.txt, don’t acters replaces acter files that ending char all char which files files * wfully_bor a first all is all files special xt, deletes the all lists .te are lists used w as e]* ˆ lists a*.txt * *.txt [ˆ m most ls ls r ls andre caret • • • • easier not Wildcards The A • • • ildcards

W .19/29 p – UNIX to or ? to Introduction An file single \ used wildcard are wildcard are of a ange est “, commands , str saf to , m r it nature in quotes containing le quotes * file’ \ special space arguments een doub file a the or ange m filename r betw ’, es a str with v ’ , e passing v m file r ha remo a quotes ’file*’ erences when ou y m diff r if file” delete single do to quote , escaping) \ acters to subtle ange ou star y (or a “str “file*” quotes are char do xample need m m acters e kslash, r r with y or • • char quote strong What Quoting Bac F Or There Ma • • • • • • •

Quoting .20/29 p – UNIX it! to Introduction An CTL-a , the realising on letters le o without tw ailab v line a are

dependent) ansposes tr command the CTL-t

(Shell commands ight, etc r line editing , editing left, line ) been e of v ly t (or mo line star ys command e to probab k emacs e y w es the v ou’v mo Y Man Arro command • • •

Editing .20/29 p – UNIX it! to Introduction An CTL-a , the realising on letters le o without list commands tw y ailab v line a vious histor are pre the

dependent) ansposes of tr command list the CTL-t through

(Shell commands e v ight, etc r editing line umbered mo , n editing a ws left, line y vi) been e of v ly arro t (or mo displa line wn star ys command do e will to probab k emacs y e y w es

the and v ou’v mo Y Man Arro histor Up command • • • • •

Editing .20/29 p – UNIX it! to Introduction An CTL-a , w the realising ne on or f ing letters le ing o without str list commands old tw str y ailab v line a with vious histor are ting pre the

dependent) ansposes of star containing substituting tr command list n command the command CTL-t through

(Shell commands nth e v last command command command command of ight, etc r editing umbered line of mo , n command last last last nth editing a ord” ws left, ord line y vi) been “w w e of v ly arro t (or Repeat last Repeat mth Repeat Repeat Repeat mo displa line wn star ys command do e will to probab w/ k emacs y e y w es [?]

the and v ou’v ing mo Y Man Arro histor Up command ing str • • • • • str !n !! ! !? !n:m !$ !n:s/old/ne

Editing .21/29 p – UNIX to f . first) ou ls y Introduction or An twice f autolist AB typing Pressing other T l . choices set hit file3 ious with t filenames & beep ar ther type v a then fur to star file2 then le and and l that need and file1, possib type file emacs commands tcsh of to files: .g. in in f e , (In list fill commands a the line to three all are of xpand present e commands list attempt a there command will if will with , see y the should AB e ks T k on or w AB ks ams xample again T r then should e or w also or ou AB Y T The It F and It prog • • • •

Completion .22/29 p – UNIX to the to Introduction An goes output and yboard e k CTL-d y b the from minated ter comes is input input ault def By Standard screen

Redirection • •

I/O .22/29 p – UNIX to the to Introduction An goes output screen. the and < on file yboard e using of k CTL-d y b the contents from redirected minated the be ter list comes is can will input input input file < ault cat def • By Standard Standard screen

Redirection • • •

I/O .22/29 p – UNIX to the to Introduction An goes output screen. .txt ls the and > file < on the file using yboard to e using of k CTL-d y b the listing file redirected contents from redirected a be minated the be ter send can list comes is can will will input input input output .txt file ls < ault > ls def • • By Standard Standard Standard screen

Redirection • • • •

I/O .22/29 p – UNIX to the to Introduction file1 An of goes 3 file output contents screen. .txt of ls the the and > file end < on the “add” the file using yboard to to e using of k CTL-d y file3 file4 b the listing in file redirected contents concatenate from redirected a append result be minated the will be ter will the send can list comes is can file3 put will > will file3 input input input output .txt file and file2 >> ls < ault > file2 cat ls file1 file4 def • • By Standard Standard Standard cat cat screen and

Redirection • • • • • •

I/O .23/29 p – UNIX to the Introduction An more of ore the bef input to the screen) to listing the y ) off a alphabetically director ies flying command the (called entr stage one of o listing of line tw the the the together more output ts output to ed the k stops sor the stac consider output .txt sends .txt more (which be ls | ls t passes the > | can -l more sor xample | | e ls more xt -l -l Pipe or • • command A F ls Pipes ls ne passing • • • • •

Pipes .24/29 p – UNIX to Introduction An nothing if PID this or umber am r n ! (Remember CTL-z prog use CTL-c process unique(ish) unning r processes use the PID a y an process unning r process process really assigned current is the (basically) the kill current is means currently will the list process PID y PID -9 will suspend quit er process o o A Ev T T kill kill else) • • • • • • •

Processes .25/29 p – UNIX to is (in am Introduction r are round the An will ou kg prog y ything & and if (quit bac an the or logout until logout doing ou command round ou y command y am) r from if type oreg f ou after prog y killed un the r the in the simply ents be to v ou y un r ue will use pre to launch round be y kg also ou & contin y shell round ma bac will the processes oreg f the should which of jobs) jobs in logout ou the command y (or round to in from job a ety control round ams oreg r n f saf kg un shell nohup r y or • o retur shell) Prog Running An Bac T F planning finished. the control • • • • • •

Job .26/29 p – UNIX to es ps v into k mo Introduction using An bac the jobs which PID jobs to bg e the v unning r round mo find then kg to ust and m bac ant e w ou v job) currently y ou mo y on the job k to that stop chec round used job (to to kg be round bac kg round can CTL-z a command bac kill oreg f command kill type the a to e round the v

II jobs ant into command ha w round the fg use oreg f job kg ou ou y y the If The Use If and bac the control • • • •

Job .27/29 p – UNIX to be utes) Introduction An min ould 5 w & ity than night ior er v am pr o r (longer the job unning alter prog r to long umber job n a a ity +19 or f ior pr unning command r a nice on nice command the assigned planning use is whole nohup are ust job the m ou y ou y Each If Thus priority • • •

Job .28/29 p – UNIX to Introduction the An use to is machine ) another er machines on lic ansf ypted tr are pub shell file Encr ( other wser remote remote a u bro commands ws es access eb men W giv allo to king y or a w netw machines x machine machine o machines easiest ssh sftp firef The Standard remote • •

Remote .29/29 p – UNIX to Introduction An ord w e-mail e files pass int logout receiv our pr y and and wledge and kno thoughts Login Change Send Edit • • • • Basic

Final .29/29 p – UNIX to Introduction An y files histor our and y confidently ord organise w e-mail wildcards processes e filesystem to files pass the ies int simple logout receiv our unning pr y w r wledge e f and about and wledge director a and e kno v kno thoughts Login Change Send Edit Use Mo Use Monitor age er • • • • • • • • v Basic A

Final