• Non ci sono risultati.

U n ix : F il e sy st em e Sh ell - 1 C o rs o d i Fond a m e n ti d i I n fo rm a tica 2 C dL Ing e gn e ri a In fo rm a tica Ing . F ra n c o Z a m bon e lli

N/A
N/A
Protected

Academic year: 2021

Condividi "U n ix : F il e sy st em e Sh ell - 1 C o rs o d i Fond a m e n ti d i I n fo rm a tica 2 C dL Ing e gn e ri a In fo rm a tica Ing . F ra n c o Z a m bon e lli"

Copied!
29
0
0

Testo completo

(1)

U n ix : F il e sy st em e Sh ell - 1 C o rs o d i Fond a m e n ti d i I n fo rm a tica 2 C dL Ing e gn e ri a In fo rm a tica Ing . F ra n c o Z a m bon e lli

IL S IS T E M A O PE RA T IV O UN IX : IL F IL E SYS T E M E L O S H E LL

Lu c id i R ea li zz a ti i n C o ll a bo ra z ion e c on :

P ro f. L e tiz ia L e on a rd i U n ive rs it à d i M od e n a

P ro f. A n ton io C o rr a d i U n ive rs it à d i B o logn a

P ro f. C esa re S te fa n e lli U n ive rs it à d i F e rr a ra

U n ix : F il e sy st em e Sh ell - 2 IL S IS T E M A O PE RA T IV O

S is te m a O pe ra tiv o c o m e g es to re ri s o rse (pe r rende re e ff ic ien te l'u s o de lle ris o rs e s ia ha rd w a re c he s o ft w a re )

S is te m a O pe ra tiv o c o m e m acc h in a v ir tu a le (pe r s e m p lif ic a re l’u s o de l s is te m a d i c a lc o lo da pa rte deg li u ten ti)

user 1 user user user 2 3 n

compiler assembler text editor data base system PROGRAMMI APPLICATIVI

SISTEMA OPERATIVO

COMPUTER

HARDWARE

(2)

U n ix : F il e sy st em e Sh ell - 3 G es tion e d e ll e R is o rse

A sse gn a z ion e d e ll e ri s o rse de l s is te m a d i c a lc o lo a i p rog ra mm i d i u ten te in ba s e a l tipo d i ric h ie s ta e ag li ob ie tt iv i da ragg iunge re (u s o e ff ic ie n te d e ll e ri s o rse )

R is o rse H w e S w : te m po d i C P U , m e m o ria , I/ O , e tc ..

* ris o lu z ione d i c on fli tt i ne ll'u s o de lle ris o rs e * sc e lta de i c ri te ri c on c u i a ss egna re una ris o rs a

D is pon ib ili tà d i a ppo s it e op e ra z ion i (sys te m ca ll ) pe r la ge s tione de lle ris o rs e

U n ix : F il e sy st em e Sh ell - 4 M acc h in a v ir tu a le

A st raz ion e p er se m p li fica re l’ u so d ell e ris o rs e e n as cond er e i d ett ag li i m p le m en ta ti v i.

E s e m p io : C on tr o ll o re d i un flopp y d isk

* nu m e ro s i c o m and i (le tt u ra , sc ritt u ra , m o v im en to de l b ra cc io , f o rm a tt a z ione de lle tr a cc e , e tc .. ) * ogn i c o m ando ha p iù p a ra m e tr i (ind iri zz o de l b lo cc o , nu m e ro d i s e tt o ri pe r tr a cc ia , e tc .. ) * nu m e ro s e c ond iz ion i d i s ta to e d i e rr o re a l c o m p le ta m en to de l c o m ando ⇓⇓ ne c e ss ità d i na sc onde re a ll'u ten te i de tt ag li ha rd w a re lega ti a l pa rti c o la re d is po s iti v o . U s o d i ope ra z ion i de l S .O . (f il e sys te m )

(3)

U n ix : F il e sy st em e Sh ell - 5 In te rf acc ia m e n to c o l S is te m a

Il s is te m a ope ra tiv o de v e rende re d is pon ib ile a ll'u ten te un m odo d i v is ua lizz a re lo s ta to de lle ris o rs e de l s is te m a , ed in te rag ire c on il s is te m a s te ss o e le s ue ris o rs e .

M S -D O S , UN IX : T u tt e le ris o rs e de l s is te m a (c on tenu to de lle m e m o rie d i m a ss a e pe rif e ric he ) v engono v is te in te rm in i d i fil e , e l'in te ra z ione u ten te -m a cc h ina v irt ua le a vv iene a tt ra v e rs o c o m a nd i s u i fil e

E se m p i:

• co m ando UN IX p er ca n ce ll ar e un fil e

RM PIPPO (il c o m ando R M o rd ina d i c an c e lla re il fil e d i no m e P IPP O )

• co m ando p er es egu ir e un p rog ra mm a a pp li ca ti vo d i no m e rea li zza to d all ’u te n te (a d es em p io , "p rog_1 .e x e" e` il fil e p rodo tt o dopo co m p il az ion e e li nk ing ):

PROG_1 (e s egu i il fil e /p rog ra mm a d i no m e P R OG _1 )

W IND O W S , M AC , O S -2 : R app re s en ta z ione g ra fic a de l s is te m a e de lle s ue ris o rs e (c on c e tt o d i sc ri va n ia " d esk top " v ir tu a le ). Le fine s tr e e le ic one rapp re s en tano ris o rs e o c on ten ito ri d i ris o rs e , c o m e s e fo ss e ro appogg ia ti s u lla sc riv an ia v irt ua le c he è lo sc he rm o . A tt ra v e rs o il m ou s e e la ta s tie ra , ag ia m o s u lle ris o rs e de l s is te m a .

U n ix : F il e sy st em e Sh ell - 6 E se m p io : VEDERE L A DA T A

In UN IX :

In W indo w s :

(4)

U n ix : F il e sy st em e Sh ell - 7 UN IX : L inguagg io co m and i

Le u tili tà de l s is te m a ope ra tiv o UN IX s ono d is pon ib ili a tt ra v e rs o un linguagg io c o m and i d ire tt a m en te in te rp re ta to da un p ro cess o re d e i c o m a nd i. Legge que llo c he no i sc riv ia m o , in te rp re tando lo c o m e c o m ando e , s e il c o m ando è c o rr e tt o , lo e s egue

I p ro c e ss o ri de i c o m and i s ono e v o lu ti da s e m p lic i ric ono sc ito ri d i c o m and i a s uppo rti pe r a m b ien ti p iù c o m p le ss i, pe r l’e s e c u z ione d i v e ri e p rop ri li nguagg i d i p rog ra mm a z ione .

Il C o n ce tt o d i P ro m p t

• In un a m b ien te in te ra tt iv o non g ra fic il p ro m p t è il s im bo lo (ad e s e m p io , una s equen z a d i c a ra tt e ri) c he v iene m o s tr a to a ll’ u ten te pe r ind ic a re c he s i a tt ende l’i mm iss ione d i un c o m ando .

IN M S D O S : no m ed riv e:\ >

IN UN IX

$

oppu re

no m ed ir ett o rio >

U n ix : F il e sy st em e Sh ell - 8 E vo lu z ione d i UN IX e P e rsona l S ys te m s

1965 M u lt ic s ( B ell T el ephon e) • 1969 UN IX p er P D P (T ho m p son & R it ch ie , T u ring Aw ar d ) • 1973 D ef in iz ion e L in g u agg io C e R is cr itt u ra UN IX in C • 1977 UN IX D is pon ib il e p er P ia tt af o rm e NON P D P • 1980 , M S -D O S 1 .0 :L a p rim a v er si on e d el si st em a op er ati vo M S -DO S er a is p ir at a a UN IX un a d ell e p rim e rea li zzaz ion i d i si st em a op er ati vo p er m ic ro co m pu te r. • 1984 : A pp le M a c In tr odu zi on e In te rf acc ia g ra fica e s is te m a a fin es tr e • 1988 : W ind o w s: n as ce c o m e in te rf acc ia g ra fica d i suppo rto al si st em a op er ati vo M S -DO S • 1993 : W ind o w s N T : i n te g ra la g es ti on e d ell a m u lti -u te n za • 1999 : W ind o w s 98 e 2000 : rea li zza il con ce tt o d i si st em a op er ati vo in te so co m e st ru m en to p er la n av ig az ion e in uno sp az io d i d ati , co m unqu e d is tr ibu it o – > IN TE RN ET

E il F u tu ro ?

• E s e c u z ione a pp li ca z ion i d is tr ibu it e e re c upe ro on - d e m a nd d i s o ft w a re (ade ss o J a v a app le t) • M ic ro -s is te m i ope ra tiv i pe r pe rs ona l d ig ita l sys te m s • N e tw o rk T e le v is ion , N e tw o rk ed H ou s e • In te rfa cc ia v o c a le e "tou c h sc reen ".

(5)

U n ix : F il e sy st em e Sh ell - 9 UN IX E F IL ES

Tu tt o il fin z ion a m e n to d e l s is te m a op e ra tiv o UN IX è C E N T RA T O S U L F IL E SYS T E M

- F IL E C O M E SE Q U E N Z A D I B Y T E N O N s ono pen s a te o rgan izz a z ion i l og ic he o a cc e ss i a re c o rd

- F IL E SYS T E M g e ra rc h ic o A L BE R O d i s o tt od ire tt o ri

- O M OG E N E IT À d is po s it iv i e fil e T U TT O è fil e

F IL E a s tr a z ione un ifi c an te de l s is te m a op e ra tiv o

fil e o rd ina ri

fil e d ire tt o ri, a cc e ss o ad a ltr i fil e

fil e s pe c ia li (d is po s iti v i fis ic i), c on tenu ti ne l d ire tt o rio /de v

U n ix : F il e sy st em e Sh ell - 10 O R G AN IZZ A Z IO N E d e l F IL E SYS T E M

N O M I d i fil e - A SS O L U T I: da lla rad ic e /no m e2 /no m e6 /f ile - R E L A T IV I: da l d ire tt o rio c o rr en te no m e6 /f ile

I no m i (e la s in ta ss i i n gene ra le ) s ono case -se n s it ive

S i po ss ono u s a re abb re v ia z ion i ne i no m i (wil d ca rd ) * pe r una qua lunque s tr inga ? pe r un qua lunque c a ra tt e re

Di re tt o rio c o rr en te iden tif ic a to da . P ad re de l d ire tt o rio c o rr en te iden tif ic a to da ..

O gn i u ten te ha un d ire tt o rio a de fau lt d ire tt o rio in c u i l 'u ten te s i c o llo c a a ll'i ng re ss o ne l s is te m a

/ (root del sistema)

nome1 nome2 nome3

nome4 nome5 nome6 nome7 nome8

file file1 file2 file3 cile filetemp

fil e * ==> fil e , f ile1 , f ile2 , f ile3 , f ile te m p fil e? ==> fil e1 , f ile2 , f ile3 *il e ==> fil e , c ile

(6)

U n ix : F il e sy st em e Sh ell - 11 A ccess o a l S is te m a O p e ra tiv o U n ix Ing ress o (L OGI N )

U se rn a m e : f ran c o P ass w o rd : **********

L 'a cc e ss o v iene v e rif ic a to a l l og in (au ten tic a z ione u ten te )

U sc ita (L OGO U T )

L 'u sc ita a vv iene s o lo a l l ogou t, t ra m ite uno de i c o m and i:

ex itlogou tC T R L -D

D u ran te una s e ss ione d i l a v o ro , i c o m and i da ti da l’u ten te s ono in te rp re ta ti da una s h e ll (in te rp re te d e i c o m a nd i)

L a s h e ll non è un ica : un s is te m a può m e tt e rne a d is po s iz ione v a rie (e a ltr e po ss ono e ss e re agg iun te )

O gn i u ten te può s p ec if ica re qu a le s h e ll d es id e ra u sa re

La s he ll a ss o c ia ta a ogn i u ten te è s pe c ifi c a ta a ll'i n te rno de l fil e /e tc /p ass w d , c he c o s tit u isc e il “da taba s e ” deg li u ten ti reg is tr a ti s u que l s is te m a (c on tu tt e le lo ro c a ra tt e ris tic he ).

U n ix : F il e sy st em e Sh ell - 12 F O R M A T O D E L F IL E /e tc /p ass w d

u te n te :p ass w o rd :U ID :G ID :c o mm e n to :d ir e tt o ri o :c o m a ndo

u te n te no m e c he b is ogna da re a l l og in p ass w o rd pa ss w o rd c he o c c o rr e da re a l l og in (m e m o ri zz a ta in fo rm a c if ra ta )

U ID U se r ID e n tif ie r nu m e ro c he iden tif ic a in m odo un iv o c o l'u ten te ne l s is te m a

GI D G roup ID e n tif ie r nu m e ro c he iden tif ic a il g ruppo d i c u i fa pa rte l'u ten te

c o mm e n to c a m po d i c o mm en to

d ir e tt o ri o d ire tt o rio in iz ia le in c u i s i tr o v a l'u ten te a l l og in (ho m e d ire c to ry )

c o m a ndo c o m ando c he v iene e s egu ito au to m a tic a m en te a ll'a tt o de l l og in (in g e n e re è un a s h e ll )

ESE M P IO:

roo t:. XP c 4 H K e0n P Q A :0 :1 :O pe ra to r:/:/ b in /s h fr an c o :r T IW 65 B O u Q 9ng :230 :30 :F ran c o Z a m bone lli :/ ho m e /f ran c o :/ b in /s h

(7)

U n ix : F il e sy st em e Sh ell - 13 S T RU TT URA D E L F IL E SYS T E M

/

b in boo t d ev u c b e tc li b lo s t+ found u s r tm p

in c lud e b in u 1 u 2

b in c o m and i p rin c ipa li d i s is te m a

d ev i d is po s iti v i

e tc , f ile s ign ifi c a tiv i pe r il s is te m a , ad e s . p ass w d c he m e m o rizz a g li u ten ti au to rizz a ti

li b , le lib re rie d i s is te m a

tm p , f ile te m po rane i

u s r, s o tt od ire tt o rio pe r u ten ti

E s is te un u ten te , roo t, p riv ileg ia to ris pe tt o ag li a ltr i: il ge s to re de l s is te m a (de tt o an c he s upe r- u s e r) c he s fugge a lle rego le d i s ic u re zz a

U n ix : F il e sy st em e Sh ell - 14 P R O T E Z IO N E d e i F il e

M o lti u ten ti



N e c e ss ità d i rego la re g li ACC ESS I a lle in fo rm a z ion i

P e r un fil e , e s is tono 3 tip i d i u tili zz a to ri: •

• il p rop rie ta rio , u se r

• il g ruppo de l p rop rie ta rio , g roup tu tt i g li a ltr i u ten ti, o th e rs

P e r ogn i tipo d i u tili zz a to re , s i d is tinguono tr e m od i d i a cc e ss o a l fil e : •

le tt u ra (r ) sc

ri tt u ra (w )

esec

u z ion e (x )

O gn i u ten te è c a ra tt e rizz a to da : •

• l’i den tif ic a to re d i u ten te (U ID , u se r ID ) e l’i den tif ic a to re d i g ruppo (GI D , g roup GI D )

O gn i fil e è m a rca to c on •

• lo U s e r- ID e il G roup -ID d e l p rop ri e ta ri o un

in s ie m e d i 12 b it d i p ro te z ione

12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 | 1 1 1 | 1 0 0 | 1 0 0 S U ID S GI D s ticky | R W X | R W X | R W X U s e r G roup O the rs

i p rim i 9 ==> tr ip le d i pe rm e ss i

(8)

U n ix : F il e sy st em e Sh ell - 15 S IG N IF ICA T O D E I 12 B IT

12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 | 1 1 1 | 1 0 0 | 1 0 0 S U ID S GI D s ticky | R W X | R W X | R W X U s e r G roup O the rs

9 b it p iù a de s tr a ( b it 1 -9 )



3 tr ip le d i pe rm e ss i: •

• ris pe tt iv a m en te pe r le tt u ra / sc ri tt u ra / esec u z ion e il p rop ri e ta ri o / qu e lli d e l s uo g ruppo / g li a lt ri

dod ic e s im o b it S U ID (S e t- U se r- ID ) ( id e n tif ica to re d i u te n te e ff e tt iv o ) S i app lic a a un fil e d i p rog ra mm a ese gu ib il e S e v a le 1 , f a s ì c he l'u ten te c he s ta e s eguendo que l p rog ra mm a v enga c on s ide ra to il p rop rie ta rio d i que l fil e (s o lo pe r la du ra ta de lla e s e c u z ione )

Q ue s to b it è ne c e ss a rio pe r c on s en tir e , du ran te l'e s e c u z ione d i que l p rog ra mm a , ope ra z ion i d i le tt u ra /sc ritt u ra s u fil e d i s is te m a , c he l'u ten te non a v rebbe il d iri tt o d i l egge re / m od ifi c a re .

E s e m p io : m k d ir c rea un d ire tt o rio , m a pe r fa rlo de - v e an c he m od ifi c a re a lc une a ree d i s is te m a (fil e d i p ro p rie tà d i roo t) , c he non po tr ebbe ro e ss e re m o d ifi - c a te da un u ten te . S o lo il S U ID l o rende po ss ib ile .

S GI D b it : c o m e S U ID b it, pe r il g ruppo s ticky b it il s is te m a c e rc a d i m an tene re in m e m o ria l’i mm ag ine de l p rog ra mm a , an c he s e non è in e s e c u z ione

U n ix : F il e sy st em e Sh ell - 16 C o ll e g a m e n ti (L in k )

Le in fo rm a z ion i c on tenu te in uno s te ss o fil e po ss ono e ss e re v is ib ili c o m e fil e d ive rs i, t ra m ite “r ife rim en ti” (li n k ) a llo s te ss o fil e fis ic o .

/ (root del sistema)

nome1 nome2 nome3

nome4 nome5 nome6 nome7 nome8

file file1 file2 file3 cile filetemp temp

Il s is te m a c on s ide ra e tr a tt a il tu tt o : •

• m en te e lim ina te s o lo s e non c i s ono a ltr i li n k a e ss o s e un fil e v iene c an c e lla to , le in fo rm a z ion i s ono v e ra - Il li

n k c a m b ia i d iri tt i?



M eg lio d i no

D ue tip i d i li n k : •

• li n k fis ic i (s i c o llegano le s tr u tt u re de l fil e sys te m) li n k s im bo lic i (s i c o llegano s o lo i no m i)

c o m a ndo : ln [- s ]

ln /no m e2 /no m e6 /f ile te m p /no m e1 /t e m p

S i v edano i li n k d i ogn i d ire tt o rio

(9)

U n ix : F il e sy st em e Sh ell - 17 SHE LL o vv e ro il P R O C ESS O R E C O M AND I

Lo s he ll i n te rp re te de i c o m and i: e s egue uno dopo l'a ltr o i c o m and i fo rn iti

loop fo re v e r < acce tt a c o m ando da c on s o le > < ese gu i c o m ando > end loop ;

Lo s he ll è un p ro cess o re c o m a nd i , c he acce tt a c o m a nd i da te rm ina le o da un fil e c o m and i e li ese gu e fi no a lla fine de l fil e (s i può u s a re < C T R L >< D > )

loop fo re v e r < L OGI N > repea t < a cc e tt a c o m ando da c on s o le > < e s egu i c o m ando > un til < fine fil e > < L OGO U T > end loop

M agg io ri c apa c ità ris pe tt o a un s e m p lic e e s e c u to re d i un c o m ando a lla v o lta

U n ix : F il e sy st em e Sh ell - 18 C O M AND I R E L A T IV I A L F IL E SYS T E M

S in ta ss i:

c o m a ndo [- op z ion i] [ a rgo m e n ti] < IN V IO >

U n c o m ando te rm ina c on un IN V IO, oppu re è s epa ra to c on ; da a ltr i c o m and i ne lla s te ss a linea

CR E A Z IO N E / G ES T IO N E D I D IR E TT O R I

m k d ir < no m ed ir> c rea z ione d i un nuo v o d ire tt o rio rm d ir < no m ed ir> c an c e lla z ione d i un d ire tt o rio c d < no m ed ir> c a m b io d i d ire tt o rio p w d s ta m pa il d ire tt o rio c o rr en te ls [< no m ed ir> ] v is ua lizz . c on tenu to de l d ire tt o rio

T RA TT A M E N T O F IL E

ln < v e cc h iono m e > < nuo v ono m e > lin k c p < fil e s o rgen te > < fil ede s tina z ione > c op ia m v < v e cc h iono m e > < nuo v ono m e > rino m . / s po s t. rm < no m e fil e > c an c e lla z ione ca t < no m e fil e > v is ua lizz a z ione

E se m p i d i c o m a nd i:

c d /no m e2 /no m e6 c a t f ile * ls /no m e1 rm *

(10)

U n ix : F il e sy st em e Sh ell - 19 P R O T E Z IO N E e D IR ITT I S U I F IL E

P e r v a ria re i b it d i p ro te z ione :

c h m od [u g o ] [ + -] [ rw x ] < no m e fil e >

I pe rm e ss i po ss ono e ss e re c on c e ss i o nega ti da l p rop ri e ta ri o d e l fil e

E s e m p io d i v a ria z ione de i b it d i p ro te z ione :

c h m od 0755 /u s r/ d ir /f il e

0 0 0 | 1 1 1 | 1 0 1 | 1 0 1 S U ID S GI D s ticky | R W X | R W X | R W X U s e r G roup O the rs

A d e s e m p io : c h m od u -w fil e im po rt a n te

A ltr i c o m and i: c ho w n < no m eu ten te > < no m e fil e > c hg rp < no m eg ruppo > < no m e fil e >

U n ix : F il e sy st em e Sh ell - 20 E se m p io , il c o m a ndo ls p e r li s ta re il c on te nu to d i un a d ir ec to ry

V a rie op z ion i: ls -a [< no m ed ir> ] v is ua lizz a fil e "na sc o s ti" (no m e c he in iz ia c on ' . ') ls -l [< no m ed ir> ] m o s tr a tu tt e le in fo rm a z ion i pe r i fil e (ti po de l fil e , pe rm e ss i, nu m e ro lin k , p rop rie ta rio ... ) ls -la [< no m ed ir> ] è l’un ione de lle p re c eden ti ls -F [< no m ed ir> ] tu tt e le in fo rm a z ion i de i fil e v is ua lizz ando i fil e no rm a li c on il l o ro no m e , g li e s egu ib ili c on no m e e s u ff iss o *, i d ire tt o ri c on no m e e s u ff iss o / ls -d [< no m ed ir> ] i d ire tt o ri s ono v is ua lizz a ti c o m e i fil e , s en z a en tr a re ne l c on tenu to e lis ta rlo ls -R [< no m ed ir> ] e s a m e ric o rs iv o de lla ge ra rc h ia a pa rti re da no m ed ir ls -i [< no m ed ir> ] lis ta g li i -nu m be r de i fil e c on le a ltr e in fo rm a z ion i ls -r [< no m ed ir> ] lis ta i fil e in o rd ine oppo s to a l no rm a le o rd ine a lfabe tic o ls -t [< no m ed ir> ] lis ta i fil e in o rd ine d i u lti m a m od ifi c a , da i p iù re c en ti, f ino a i m eno re c en ti

(11)

U n ix : F il e sy st em e Sh ell - 21 A LT R I C O M AND I D I S IS T E M A

• I fil e s ono c on s ide ra ti i n s ie m i d i linee , f a tt e da pa ro le • Le pa ro le s ono s equen z e d i c a ra tt e ri, s epa ra te da s pa z i

m o re < no m e fil e > una pag ina pe r v o lta s o rt < no m e fil e > o rd ina a lfabe tic a m en te s o rt [-

• M o lte op z ion i: r] < no m e fil e > (r = in o rd ine in v e rs o ) u -o sc ita s u fil e op z ione < no m e fil eou t>

d iff < fil e1 > < fil e2 > m o s tr a s o lo le righe d iv e rs e find < d ire tt o rio > -n a m e < no m e fil e > -p ri n t c e rc a no m e fil e in d ire tt o rio w c [- lw c ] [ < no m e fil e > ] c on ta le linee (op z ione

fil e c c a ra tt e ri (op z ione ) de llo s tanda rd inpu t o de l l) , o le pa ro le (op z ione w ), o i

C OM AND I d i S T A T O de l s is te m a

d a te da ta e o ra a tt ua le tim e c rono m e tr a l’e s e c u z ione d i un c o m ando w ho m o s tr a g li u ten ti a tt ua lm en te c o llega ti p s m o s tr a i p ro c e ss i c o rr en ti ne l s is te m a s lee p s o s pende il p ro c e ss o quando s pe c ifi c a to m a n < c o m ando > m o s tr a l’he lp (gu ida ) de l c o m ando ESE M P IO : da te ; t im e ; w ho ; p s

U n ix : F il e sy st em e Sh ell - 22 R ID IR E Z IO N E D E LL 'I/ O

T u tt i i c o m and i d i UN IX s ono fil tr i

U n fil tr o è un p rog ra mm a c he ric e v e in ing re ss o da un inpu t e p rodu c e ris u lta ti s u ou tpu t (uno o p iù )

s ta nd a rd inpu

t



c on s o le s ta nd a rd ou tpu t



c on s o le s ta nd a rd e rr o r



c on s o le

stdinput stdoutput

stderror FILTRO

I f ilt ri po ss ono ope ra re s u ll’i npu t c on s ide rando lo a linee

m o re s ta m pa una pag ina pe r v o lta s o rt o rd ina a lfabe tic a m en te le linee g re p < s tr inga > c e rc a la s tr inga ne l fil e rev riba lta ogn i s ingo la linea tee < fil e > c op ia l’i npu t s ia s u ll’ ou tpu t s ia s u l fil e h ea d [- nu m e ro linee ] fil tr a le p rim e linee de l fil e ta il [- nu m e ro linee ] fil tr a le u lti m e linee de l fil e a w k tr a s fo rm a le s tr inghe d i un fil e s e c ondo c e rte rego le

C on c e tt o d i fil tr agg io e rid ire z ione F O ND A M E N T A L E pe r la c o m po s iz ion e d i p rog ra mm i d i tr a tt a m en to da ti i n UN IX .

(12)

U n ix : F il e sy st em e Sh ell - 23 O gn i c o m ando può e ss e re rid ire tt o s u un fil e d iv e rs o se n z a ca m b ia re il c o m a ndo

c o m p le ta O M OG E N E IT À fr a d is po s it iv i e fil es

ri d ir e z ion e d e ll'i npu t

< c o m ando > < < fil e inpu t>

ri d ir e z ion e ou tpu t

< c o m ando > > < fil eou tpu t> risc riv e il fil eou tpu t

< c o m ando > >> < fil eou tpu t> appende a fil eou tpu t

A lc un i ese m p i d i ri d ir e z ion e :

ls -lga > fil e

ls > /t m p /f ile c d /t m p s o rt < fil e > fil e te m p re v < fil e te m p > fil e m o re < fil e te m p fil e rm fil e fil e te m p

w ho > te m p w c -l te m p

p s > fil e

U n ix : F il e sy st em e Sh ell - 24 R ID IR E Z IO N E (es te n s ion i)

O gn i co m ando tr ova ape rti s td in , s tdou t, s tde rr

R ID IR E Z IO N E M U LT IP L A In c a s o d i rid ire z ione , il fil e d i i ng re ss o è ape rto in le tt u ra , il fil e d i ou tpu t ape rto in sc ritt u ra (c io è c rea to v uo to )

c o m ando > fil e1 < fil e2 > fil e3 < fil e 4 > fil e5 Il c o m ando e s egue c on s td in da fil e4 e s tdou t s u fil e5

E FF E TT I C O LL A T E RA L I d is tr u z ione de i fil e fil e1 e fil e3

A LT R I F IL E In B ou rne S he ll è po ss ib ile an c he : •

• in v o c a z ione de l c o m ando u s a re a ltr i fil e in rid ire z ione , s pe c ifi c ando li a lla aggan

c ia re p iù ou tpu t ad uno s te ss o fil e

c o m ando 2 > fil e2 3 > fil e3 5 > fil e5 S i ric h iede la ape rtu ra de l fil e2 c on c h ia v e 2 , de l fil e 3 c on c h ia v e 3 , e tc .

c o m a ndo & > 2 L 'u sc it a d e l c o m a ndo v ie n e fo rz a ta s u ll o s td e rr o r

S i no ti c he la nu m e ra z ione p ro s egue da i fil e s tanda rd : s td in = 0 , s tdou t = 1 , s td e rr = 2 , ...

(13)

U n ix : F il e sy st em e Sh ell - 25 P IPE

C O LL E G A M E N T O AU T O M A T IC O d i c o m and i

La P IPE (tubo ) c o ll e g a l'ou tpu t d i un c o m ando c on l'i npu t de l s u cc e ss iv o

S CH E M A IM P L E M E N T A T IV O

filetran comando1 comando2

< c o m ando1 > > < fil e tr an > ; < c o m ando2 > < < fil e tr an >

| comando1 comando2

< c o m ando1 > | < c o m ando2 >

In D O S



R EA L IZZ A Z IO N E c on F IL E T E M P O RAN E I

In UN IX



P IPE c o m e C O S T RU TT O P ARA LL E L O

le p ipe s ono sv o lte in m odo pa ra lle lo (ogn i c o m ando è m appa to in un p ro c e ss o )

I c o m and i de lla p ipe p ro c edono in pa ra lle lo tr a lo ro



N O N s i c reano fil e te m po rane i M en tr e un c o m ando p rodu c e l’ou tpu t, l’a ltr o lo c on s u m a

U n ix : F il e sy st em e Sh ell - 26 E se m p i d i p ip ing :

w ho | w c -l c on ta g li u ten ti c o llega ti

ls -R | m o re

re v < fil e1 | s o rt | re v | m o re

p ro v a re le d iff e ren z e tr a le p ipe in U n ix e in D O S

(14)

U n ix : F il e sy st em e Sh ell - 27 D e fin iz ion e d i p ro cess o In fo rm a lm en te , il te rm ine p ro c e ss o v iene u s a to pe r ind ic a re un p rog ra mm a in esec u z ion e

E s e c u z ione s equen z ia le de l p ro c e ss o ; is tr u z ion i e s egu ite una dopo l’a ltr a

D iff e re n z a tr a p ro cess o e p rog ra mm a

P rog ra mm a : e n tit à p ass iva c he de sc riv e le a z ion i da c o m p ie re

P ro c e ss o : e n tit à a tt iva c he rapp re s en ta l'e s e c u z ione d i ta li a z ion i

In un s is te m a m u lti ta sk ing p p ro c e ss i po ss ono e ss e re in e s e c u z ione " c on c o rr e n te m e n te "

U n ix : F il e sy st em e Sh ell - 28 R IE N T RAN Z A D E LL O S H E LL

U no s he ll è un p rog ra mm a c he e s egue i c o m and i, fo rn iti da te rm ina le o da fil e

S i i n v o c ano g li s he ll c o m e i no rm a li c o m and i e s egu ib ili c on il l o ro no m e s h [< fil e c o m and i> ] cs h [< fil e c o m and i> ]

Le in v o c a z ion i a tt iv ano un p ro c e ss o c he e s egue lo s he ll

G li s h e ll s ono R IE N T RAN T

I:

p iù p ro cess i po ss ono c ond iv id e re il c od ice se n z a e rr o ri e d in te rf e re n z e

s h s h cs h p s # quan ti p ro c e ss i s i v edono?

(15)

U n ix : F il e sy st em e Sh ell - 29 M E T ACARA TT E R I

Lo S H E LL ric ono sc e c a ra tt e ri s pe c ia li (W IL D C A RD )

* una qua lunque s tr inga d i z e ro o p iù c a ra tt e ri in un no m e d i fil e

? un qua lunque c a ra tt e re in un no m e d i fil e

[ccc

] un qua lunque c a ra tt e re , in un no m e d i fil e , c o m p re s o tr a que lli ne ll'i n s ie m e . A n c he ra ng e d i v a lo ri:

[c -c

]

P e r e s e m p io ls [q -s ]* li s ta i fil e c on no m i c he in iz iano c on un c a ra tt e re c o m p re s o tr a q e s

# c o mm en to fino a lla fine de lla linea \ e sc ape (s egna la d i non in te rp re ta re il c a ra tt e re s u cc e ss iv o c o m e s pe c ia le ) Il c o m ando ec ho sc riv e la s tr inga s u cc e ss iv a ec ho * s ta m pa tu tt i i no m i d i fil e de l d ire tt o rio c o rr en te ec ho \* s ta m pa il c a ra tt e re a s te risc o ‘*

ls [a -p ,1 -7 ]* [c ,f ,d ]? e len c a i fil e i c u i no m i hanno c o m e in iz ia le un c a ra tt e re c o m p re s o tr a 'a e 'p ' oppu re tr a 1 e 7 , e il c u i penu lti m o c a ra tt e re s ia 'c ', 'f', o 'd '

U n ix : F il e sy st em e Sh ell - 30 ESE CU Z IO N E d i C O M AND I i n S H E LL

In UN IX ogn i c o m ando è e s egu ito da una nuo v a s he ll

La s h e ll a tt iva m e tt e in e s e c u z ione una sec ond a s h e ll

La sec ond a s h e ll

• pa ra m e tr i e s egue le s o s tit u z ion i de i m e ta c a ra tt e ri e de i

• c e rc a il c o m ando e s egue il c o m ando

Lo s h e ll p a d re a tt ende il c o m p le ta m en to de ll'e s e c u z ione de lla s o tt o -s he ll (c o m po rta m en to s in c rono )

SHELL 1 SHELL 2

termine attesa comando

A M B IE N T E D I S H E LL (e n v ir on m e n t) : in s ie m e d i v a riab ili d i s he ll, pe r e s e m p io : • una v a riab ile reg is tr a il d ir e tt o ri o c o rr e n te • ogn i u ten te s pe c ifi c a c o m e fa re la ric e rc a de i c o m and i ne i v a ri d ire tt o ri de l fil e sys te m : v a riab ile P A T H ind ic a i d ire tt o ri i n c u i c e rc a re • la v a riab ile H O M E ind ic a il d ire tt o rio d i a cc e ss o in iz ia le .

(16)

U n ix : F il e sy st em e Sh ell - 31 S CH E M A d i un P R O C ESS O R E C O M AND I

p ro c edu re s h e ll ( a m b ien te , f ile c o m and i); < e red ita a m b ien te (e s po rta to ) de l pad re , v ia c op ia > beg in repea t < legg i c o m ando da fil e c o m and i> if < è c o m a ndo a m b ie n te > then < m od ifi c a d ire tt a m en te a m b ien te > ; e ls e if < è c o m a ndo ese gu ib il e > then < e s e c u z ione de l c o m ando v ia nuo v a s he ll> e ls e if < è nuo v o fil ec o m a nd i> then s he ll (a m b ien te , nuo v o fil e c o m and i); e ls e < e rr o re > ; end if un til < fine fil e > end s he ll;

P e r abo rti re il c o m ando c o rr en te : C T R L -C

N on c rea re un fil e c o m and i ric o rs iv i s en z a una c ond iz ione d i te rm ina z ione !!

U n ix : F il e sy st em e Sh ell - 32 V a ri a b ili n e ll a s h e ll

O gn i s he ll de fin isc e :

• un

in s ie m e d i v a riab ili (tr a tt a te c o m e s tr inghe ) c on no m e e va lo re

• i

rif e rim en ti a i v a lo ri de lle v a riab ili s i fanno c on $ no m eva ri a b il e

• s

i po ss ono fa re asse gn a m e n ti

no m eva ri a b il e = $ no m eva ri a b il e l-v a lue r- v a lue

E s e m p i:

x = 123ab c # non s i de v ono u s a re b lan k e c ho $ x # v is ua lizz a 123ab c

(17)

U n ix : F il e sy st em e Sh ell - 33 S o s tit u z ion i d e ll a s h e ll (p a rs ing ) P rim a de lla e s e c u z ione , il c o m ando v iene sc and ito (pa rs ing ), a lla ric e rc a d i c a ra tt e ri s pe c ia li (* , ? , $ , > , < , |, e tc .)

C o m e p rim a c o s a , lo s he ll p repa ra i c o m and i c o m e fil tr i: ri d ir e z ion e e p ip ing d i i ng ress o u sc it a (s u fil e o d is po s it iv o )

N e lle s u cc e ss iv e sc an s ion i, s e la s he ll tr o v a a ltr i c a ra tt e ri s pe c ia li, p rodu c e de lle s o s tit u z ion i

1 ) S o s tit u z ion e d e i c o m a nd i I c o m and i c on tenu ti tr a ` ` ( ba ck quo te ) s ono ese gu it i e ne v iene p rodo tt o il ris u lta to

e c ho `p w d ` # s ta m pa il d ire tt o rio c o rr en te

`p w d ` # ten ta d i e s egu ire /ho m e /pao lo

`p w d

`/f ilee x e .e x e # e c o s ì ?

2 ) S o s tit u z ion e d e ll e va ri a b ili e d e i p a ra m e tr i I no m i de lle v a riab ili ($ no m e ) s ono es p a n s i ne i v a lo ri c o rr is ponden ti

x = a lfa # non s i de v ono u s a re b lan k e c ho $ x # p rodu c e a lfa

3 ) S o s tit u z ion e d e i no m i d i fil e I m e ta c a ra tt e ri *, ? , [ ] s ono es p a n s i n e i no m i d i fil e s e c ondo un m e cc an is m o d i pa tt e rn m a tc h ing

U n ix : F il e sy st em e Sh ell - 34 S o s tit u z ion i d e ll a s h e ll

C o m e s i è v is to , la s he ll ope ra c on s o s tit u z ion i te s tua li s u l c o m ando e p repa ra l'a m b ien te d i e s e c u z ione pe r il c o m ando s te ss o

R iass un to fas i rid ire z ione e p ip ing e le fa s i d i s o s tit u z ion i: 1 ) s o s tit u z ione c o m and i 2 ) s o s tit u z ione v a riab ili e pa ra m e tr i 3 ) e s pan s ione de i no m i d i fil e

C o m a nd i re la tiv i a l c on tr o ll o d e ll 'es p a n s ion e :

' ( quo te ) ne ss una e s pan s ione (né 1 , né 2 , né 3 )

" ( doub lequo te ) s o lo s o s tit u z ion i 1 e 2 (non la 3 )

y = 3 e c ho ' * e $ y ' # p rodu c e * e $ y e c ho " * e $ y " # p rodu c e * e 3 e c ho "` p w d `" # s ta m pa no m e d ir c o rr en te

s ia " c he ' im ped isc ono a lla s he ll d i i n te rp re ta re i c a ra tt e ri s pe c ia li pe r la rid ire z ione (< > >> ) e pe r il p ip ing ( | )

(18)

U n ix : F il e sy st em e Sh ell - 35 S o s tit u z ion i d e ll a s h e ll : E se m p i

R ia ss un to fa s i rid ire z ione e p ip ing e le fa s i d i s o s tit u z ion i: 1 ) s o s tit u z ione c o m and i 2 ) s o s tit u z ione v a riab ili e pa ra m e tr i 3 ) e s pan s ione de i no m i d i fil e

S c an s ione de lla linea d i c o m ando c on p iù pa ss a te s u cc e ss iv e (una pe r c ia sc una fa s e ).

E s e m p i: $ es = '?? ' $ $es tt: e x e c u te pe rm iss ion den ied $ s he ll e s egue fa s i 1 , 2 (s o s tit u z ione d i e s c on ?? ), 3 (s o s tit u z ione d i ?? c on il fil e de l d ir c o rr en te tt ) e p ro v a qu ind i ad e s egu ire tt c he non ha pe ro ' i d iri tt i d i e s e c u z ione $ rr = `p w d ` $ ec ho $ rr `p w d ` s he ll e s egue fa s i 1 , 2 (s o s tit u z ione rr) , 3 , ed e s egue qu ind i e c ho '`p w d `'

U n ix : F il e sy st em e Sh ell - 36 A TT E N Z IO N E :

La s he ll e s egue un a s o la es p a n s ion e d i c iasc un tipo (c o m and i, v a riab ili , m e ta c a ra tt e ri no m i fil e )

y = 3 x = '$ y ' e c ho $ x # s ta m pa $ y (pe rc hé x v a le $ y )

P e r o tt ene re una u lte rio re s o s tit u z ione , s e ric h ie s ta , b is ogna F O R Z AR L A



eva l

e v a l e c ho $ x # s ta m pa 3 (pe rc hé v a lu ta $ y )

eva l e s egue il c o m ando pa ss a to c o m e a rgo m en to (dopo c he la s he ll ne ha fa tt o il pa rs ing ). eva l c on s en te qu ind i una u lte rio re fa s e d i s o s tit u z ione

E s e m p io :

$ p = 'l s |m o re ' $ $ p ls| m o re : e x e c u te pe rm iss ion den ied $ $ eva l $ p 5_6_98 c lien t 5_6_98 s e rv e r A sc ii_p ic A tt r … .

(19)

U n ix : F il e sy st em e Sh ell - 37 E sec u z ion e d i un C O M AND O

SHELL 1 SHELL 2

sul comando sostituzioni

comando Esecuzione

file file input output

Il c o m ando ese gu e a v endo c o llega to •

• il fil e d i i npu t p rop rio inpu t a l s pe c ifi c a ti da lla s h e ll d i l a n c io il fil e d i ou tpu t p rop rio ou tpu t a l

U n ix : F il e sy st em e Sh ell - 38 ESE CU Z IO N E IN P ARA LL E L O &

Lo s he ll pad re a s pe tt a il c o m p le ta m en to de l fig lio e s e c u z ione in fo re g round ( s in c ron a )

È po ss ib ile non a s pe tt a re il fig lio , m a p ro s egu ire e s e c u z ione in b ack g round ( as in c ron a )

Lo s he ll i n v o c an te è imm ed ia ta m en te a tt iv o

< c o m ando > [< a rgo m en ti> ] & P ro cess ID : < nu m b e r> Id e n tif ica to re d e l p ro cess o in ba ck g round Q uando te rm ina lo s he ll pad re v iene a vv is a to

I p ro c e ss i i n ba ck g round s i e lim inano c on k ill < P ID >

I p ro c e ss i i n ba ck g round m andano l'ou tpu t s u lla c on s o le s i po ss ono m e sc o la re i m e ss agg i d i d iv e rs i p ro c e ss i

D e v ono p rende re l'inpu t da fil e (r id ir e z ion e ) a ltr im en ti c i s a rebbe c on fu s ione s u ll'i npu t (IN T E R F E R E N Z A )

SHELL PADRE SHELL FIGLIO

non si attende PID

terminato

(20)

U n ix : F il e sy st em e Sh ell - 39 P R OG RA MM A Z IO N E N E LL O S H E LL

Il P R O C ESS O R E C O M A ND I è in g rado d i e labo ra re c o m and i p rendendo li da un fil e



f il e c o m a nd i

L ingu a gg io C o m a nd i

U n fil e c o m a nd i può c o m p rende re •

• s ta te m en t pe r il c on tr o llo d i flu ss o

• v a riab ili pa

ss agg io de i pa ra m e tr i

N .B . qua li s ta te m en t s ono d is pon ib ili d ipende da qua le s he ll u s ia m o

S H E LL D I B O URN E (/b in /s h )

U s a ta c o m e li nguagg io p ro to tipa le d i s is te m a pe r il ra p ido sv il uppo de lle app lic a z ion i

Lo s he ll è case se n s it ive

P e r fa re e s egu ire un fil e c o m and i (m y F ile ):

• o

s i rende e s egu ib ile il fil e e po i l o s i l an c ia :

c h m od + x m y F ile ; m y F ile

• oppu

re s i può in v o c a re d ire tt a m en te una s he ll c he lo e s egua : s h m y F ile

U n ix : F il e sy st em e Sh ell - 40 V AR IAB IL I

S ono d is pon ib ili va ri a b ili c he c on tengono s tr inghe N O N è ne c e ss a ria la de fin iz ione de lle v a riab ili

Il no m e de lle v a riab ili è libe ro (a lc une p rede fin ite ) Il c on tenu to de lle v a riab ili è ind ic a to da l m e ta c a ra tt e re $

e c ho $ H O M E # s ta m pa il d ire tt o rio d i de fau lt

e c ho PA T H $ P A T H # s ta m pa PA T H /:/ b in :$ H O M E :. (iI c a ra tt e re ':' è il s epa ra to re de i v a ri c a m p i i n PA T H )

A sse gn a m e n to < va ri a b il e >=< va lo re > # n ie n te s p a z i! i= 12 e c ho i $ i j= $ i+ 1 e c ho $ j

La p rim a e c ho fo rn isc e la s tr inga i 12 la s e c onda e c ho fo rn isc e la s tr inga 12 + 1

L e va ri a b ili s ono tr a tt a te c o m e s tr ingh e d i ca ra tt e ri

v = "ls -F " ; $ v v 2 = "ls -lga a *" $ v 2 # a l m o m en to de ll’i n v o c a z ione , v iene e s pan s o in # “tu tt i i fil e de l d ir. c o rr en te c he in iz iano pe r a ”

e c ho $ v ; e c ho v ; e c ho `$ v `

Riferimenti

Documenti correlati

5 - 52024 Loro Ciuffenna (AR); in questo caso per la data di presentazione farà fede il timbro postale. La domanda dovrà comunque pervenire inderogabilmente

RILEVATA la necessità di precisare le modalità di determinazione degli oneri in presenza di suddivisioni immobiliari, sia nel caso di suddivisione di interi

[r]

.LOOP Start; se CX diverso da zero; salta

[r]

Non e’ necessa rio“percepire” il fatto che il documento sia sul file system localeo su una macchina

Identical Parallel-machine: notazione »Si vuoleformulareilseguenteproblemadi scheduling: »Datidel problema: ›Insiemedeijob J= {1, …, n} ›InsiemedimacchineM= {1,…, m} ›Per

[r]