Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Principali comandi del Sistema Operativo Unix Christian: The Unix Operating System Redivo – Zaglia: Unix Bourne: The Unix System Quartiroli – Fusaro.

Similar presentations


Presentation on theme: "1 Principali comandi del Sistema Operativo Unix Christian: The Unix Operating System Redivo – Zaglia: Unix Bourne: The Unix System Quartiroli – Fusaro."— Presentation transcript:

1 1 Principali comandi del Sistema Operativo Unix Christian: The Unix Operating System Redivo – Zaglia: Unix Bourne: The Unix System Quartiroli – Fusaro – Smareglia: Unix

2 2 Uso del manuale in linea $> man who WHO (1) USER COMMANDS WHO (1) NAME who – who is logged in on the system SYNOPSIS: who [ who-file ] [ am i ] DESCRIPTION:...............

3 3 Uso del manuale in linea $> apropos who who - who's logged in whoami - display current user w- what everyone is doing $> apropos logged logname-get the name you are using w- what everyone is doing

4 4 Il file system delle macchine Unix per la didattica / docenti... local home... usr lib bin st375409 labgroup st343920 tecnici tesisti studenti

5 5 Come muoversi nel File System $> pwd /* path to current directory */ /usr/home/studenti/st93302 $> cd mydir /* change directory */ $> pwd /usr/home/studenti/st93302/mydir

6 6 Come muoversi nel File System $> cd /usr/home/studenti /* change dir with */ $> pwd /* with absolute path */ /usr/home/studenti $> cd st93302/mydir /* change dir with */ $> pwd /* with relative path */ /usr/home/studenti/st93302/mydir $> cd /* change to home directory */

7 7 Come muoversi nel File System $> pwd /usr/home/studenti/st93302 $> cd.. /* change to parent directory */ $> pwd /usr/home/studenti $> pwd /usr/home/studenti/st93302 $> cd. /*. is the current directory */ $> pwd /usr/home/studenti/st93302

8 8 Manipolazione dei file $> ls/* list current directory */ pippoplutoprogram.c $> ls /usr/home/* list specified directory */ docentistudentitecnicitesisti /usr/home/studenti $> ls -l/* list protections, owner and size */ -rw-r--r--st30221 lab01 125 Nov 12 13:15 pippo.c -r-xr-xr-xst30221 lab01 670 Nov 11 10:10 pluto.c

9 9 Manipolazione dei file $> ls -la/* list also current and parent dir */ -rw-r--r--st30221 lab01 81 Oct 10 23:05. -rw-r--r--st30221 lab01 75 Oct 10 09:12.. -rw-r--r--st30221 lab01 125 Nov 12 13:15 pippo.c -r-xr-xr-xst30221 lab01 670 Nov 11 10:10 pluto.c

10 10 Manipolazione dei file $> cat pippo.c /* show content of file */ #include main() int i1 = 0; char c1,c2;....... $> more pippo.c /* show content of file in pages use "space" or "enter" to advance */

11 11 Manipolazione dei file $> cp pluto pippo/* copy pluto onto pippo */ /* old pluto – if any – is lost */ $> mv pluto pippo/* change name of pluto */ /* old pippo – if any – is lost */ $> rm pluto pippo/* remove specified files */ $> mkdir new-dir/* make new directory */

12 12 Manipolazione dei file $> rmdir new-dir/* remove new-dir */ /* only if empty */ $> rm –r new-dir/* recursively remove */ /* new-dir */ $> wc file /* counts lines words, chars in file */ $> wc -l file /* counts lines in file */

13 13 Manipolazione dei file $> diff f1 f2/* lists diffs between f1 and f2 */ $> grep STR file(s)/* search STR in file(s) */ $> file prog.c /* file type */ prova.c : c program text $>find DIR -name FILE -print/* search FILE */ /* in DIR recursively */

14 14 Manipolazione dei file $>find DIR -name "*STR*" -print /* search for file names containing STR */ /* in DIR recursively */ $> du /* disk usage (in blocks) */

15 15 Protezione dei file in Unix Tre tipi di protezione: –lettura: r –scrittura: w –esecuzione: x Tre livelli di protezione: –utente: u –gruppo: g –gli altri: o –utente + gruppo + gli altri: a

16 16 Protezione dei file in Unix $> ls -l pippo -rw-r--r-- st30221......... pippo $> chmod u+x pippo /* allows execution to owner */ $> ls -l pippo -rwxr--r-- st30221......... pippo

17 17 Protezione dei file in Unix $> ls -l pippo -rwxr----- st30221......... pippo $> chmod go+rx pippo /* allows read and execution to */ /* group and others */ $> ls -l pippo -rwxr-xr-x st30221......... pippo

18 18 Protezione dei file in Unix $> ls -l new-dir drwxrwxrwx st30221......... new-dir $> chmod a-rw new-dir /* forbids read and write */ /* to everyone */ $> ls -l new-dir d--x--x--x st30221......... new-dir

19 19 cambiamento di appartenenza dei file in Unix $> ls -l -rw-r--r--st30221 lab01 125 Nov 12 13:15 pippo.c -r-xr-xr-xst30221 lab01 670 Nov 11 10:10 pluto.c $> chown st96932 pippo.c /*change owner of file */ $> ls -l -rw-r--r--st96932 lab01 125 Nov 12 13:15 pippo.c -r-xr-xr-xst30221 lab01 670 Nov 11 10:10 pluto.c

20 20 Gestione dei processi in Unix $> ps /* show Process Status of terminal */ PIDTTSTAT TIMECOMMAND 1418 p0S 0:01-csh (csh) 1423p0R 0:00ps $> ps agx /*shows all processes */ $> ctrl-C/* kills a running process */ $> ctrl-Z/* suspends a running process */

21 21 Foreground e Background Normalmente, quando lanciate un comando o un eseguibile, il controllo del terminale (il prompt) ritorna solo alla terminazione del processo corrispondente: myprompt> sleep 10; echo "ciao!"/* waits 10 seconds */... for 10 seconds nothing happens...... no other commands can be run until 10 sec. expire ciao! myprompt> Questa e' l'esecuzione dei processi in foreground

22 22 Foreground e Background Tuttavia e' possibile lanciare un comando o un programma, e mentre il processo relativo e' in esecuzione eseguire altri comandi/programmi myprompt> sleep 10; echo "ciao!" &/* waits 10 seconds * myprompt> date Mon Nov 12 16:31:13 2001 myprompt> cp pippo pluto myprompt>... /* and 10 seconds later: */ ciao! Questa e' l'esecuzione dei processi in background

23 23 Foreground e Background $> ctrl-Z/* suspends a foreground running process */ $> fg /* resume in foreground a suspended process */ $> bg /* resume in background a suspended process */ $> jobs /* shows background processes */

24 24 Uccisione di un processo in Unix $> ps /* show Process Status of terminal */ PIDTTSTAT TIMECOMMAND 1418 p0S 0:01-csh (csh) 1419 p0R 0:50a.out 1234 p0R 0:00ps $> kill 1419/* kill the specified process */ $> kill -9 1419 /* 1419 cannot ignore kill */ SIGKILL

25 25 Alcuni metacaratteri C-Shell $> !! /* re-executes last issued command */ $> !w/* re-executes last command starting with "w" */ $> ls *.c /* asterisk = subsitute for everything */ $> ls > pippo /* output redirection */ $> cat pippo prova.c prog.c

26 26 Alcuni metacaratteri C-Shell \METACHAR/* escape for METACHARS */ $> cp pippo <> /* error of redirection */ $> cp pippo \ /* creates a file called <> */

27 27 File speciali C-Shell.login/* configures login session */.cshrc /* set aliases, seraching paths,... */ alias ll "ls -l"/* renames "ls -l" as ll */ $> source.cshrc /* re-read.cshrc – useful if searching paths are changed */

28 28 File speciali C-Shell.history/* remembers last issued commands */ $> history [n] /* shows last n issued commands */ 41ls 42date 43vi pippo.c 44lpr pippo.c 45pwd $> !44/* re-issues command n. 44 */ lpr pippo.c

29 29 File speciali C-Shell $> history [n] /* shows last n issued commands */ 41ls mydir 42date 43vi pippo.c $> !ls/* re-issues last "ls" command */ ls mydir $> cd !$/* !$ is the last arg. of previous command */ cd mydir

30 30 Text editor "vi" Per scrivere un file in Unix potete usare uno degli editor disponibili: "pico", "gvi", "vi". pico e gvi sono editor moderni, in cui potete manipolare il testo usando mouse e frecce. gvi accetta anche tutti i comandi di vi. vi e' l'editor di default in Unix. E' difficile da usare, perche' e' stato sviluppato quando non esistevano le moderne interfacce grafiche, e il mouse non era ancora stato inventato. vi e' molto potente, e i suoi comandi possono persino essere messi in un file ed eseguiti separatamente.

31 31 Text editor "vi" In vi esistono due modalita': COMANDO, usata per spostarsi nel testo, cancellare, duplicare, sostituire, cercare, etc. INSERZIONE, per inserire testo. Si passa da una modalita' all'altra con opportuni comandi $> vi prova.c /* creates or open prova.c */ quando editate un file, inizialmente siete in modalita' COMANDO

32 32 Text editor "vi" MODO "COMANDO": come uscire dall'editor :wq /* quit editor saving changes */ ZZ /* quit editor saving changes */ :w/* save changes without quitting */ :q/* quit editor without saving changes */ :q! /* quit editor without saving changes */

33 33 Text editor "vi" MODO "COMANDO": come spostarsi nel file h /* moves left of one character */ l /* moves right of one character */ j/* moves down of one line */ k/* moves up of one line */ ctrl-U /* moves up of a few lines */ ctrl-D/* moves down of a few lines */ G/* goes to the end of file */ nG/* goes to line number n of file */

34 34 Text editor "vi" MODO "COMANDO": come cancellare x /* deletes current character */ dd /* deletes current line */ dw/* deletes current word */ nx/* deletes n chars from cursor to the right */ ndd/* deletes n lines downward */ ndw/* deletes n words from cursor to the right */

35 35 Text editor "vi" MODO "COMANDO": altri comandi utili rx /* replaces current char with char x */. /* repeats last command */ u/* undo last command */ /string/* searches first occurence of string in file downward */ ?string/* searches first occurence of string in file upward */ n/* after a search command, repeats search */

36 36 Text editor "vi" MODO "COMANDO": altri comandi utili nyy /* copies n lines in a local buffer. Useful to copy lines in different parts of the text */ p /* puts content of buffer starting at the cursor position */ il comando "p" puo' essere usato per inserire il contenuto del buffer locale del vi. Questo buffer viene riempito non solo dal comando "yy", ma anche, ogni qual volta si usa un comando di cancellazione, con la parte di testo cancellata. Cosi' e' possibile spostare porzioni di testo da una parte all'altra del file.

37 37 Text editor "vi" MODO "COMANDO": altri comandi utili % /* if cursor is on a parenthesis, it goes to the corresponding balancing parenthesis */ "%" e' utile quando si scrivono programmi in C per controllare il bilanciamento delle parentesi dei costrutti :s/OLD/NEW/g /* replaces every occurence of OLD string with NEW string in file */ mLETTER /* mark the current line with LETTER */ :'a,'bw FILE/* writes the part of file between the two marker letters "a" and "b" in a new FILE */

38 38 Text editor "vi" MODO "COMANDO": altri comandi utili :r FILENAME /* insert the content of FILENAME in the current file starting at cursor position */ :set number /* sets line numbering of file */ :set nonumber /* removes line numbering of file */

39 39 Text editor "vi" passaggio dal modo "COMANDO"al modo "INSERZIONE" i /* to insert text from the cursor position */ a /* to append text from char next to cursor position. Useful to append text at the end of lines */ o /* open a new line for text insertion below the cursor */ O /* open a new line for text insertion above the cursor */ s /* substitutes current char with new text */ ns /* substitutes n chars from cursor with new text */ cw /* change word */

40 40 Text editor "vi" passaggio dal modo "INSERZIONE"al modo "COMANDO" In ogni momento, per passare dalla modalita' INSERZIONE a quella di comando, basta digitare il tasto ESCAPE.

41 41 Uso del compilatore C $> gcc file.c /* creates an executable program called a.out */ $>a.out/* runs a.out */ $> gcc file.c -o myprogram /* creates an executable called myprogram */


Download ppt "1 Principali comandi del Sistema Operativo Unix Christian: The Unix Operating System Redivo – Zaglia: Unix Bourne: The Unix System Quartiroli – Fusaro."

Similar presentations


Ads by Google