Title: Principali comandi del Sistema Operativo Unix
1Principali comandi del Sistema Operativo Unix
- Christian The Unix Operating System
- Redivo Zaglia Unix
- Bourne The Unix System
- Quartiroli Fusaro Smareglia Unix
2Uso del manuale in linea
- gt man who
- WHO (1) USER COMMANDS WHO (1)
- NAME
- who who is logged in on the system
- SYNOPSIS
- who who-file am i
- DESCRIPTION
- ...............
3Uso del manuale in linea
- gt apropos who
- who - who's logged in
- whoami - display current user
- w - what everyone is doing
- gt apropos logged
- logname -get the name you are using
- w - what everyone is doing
4Il file system delle macchine Unix per la
didattica
/
...
home
local
tesisti
studenti
docenti
tecnici
labgroup
st343920
st375409
5Come muoversi nel File System
- gt pwd / path to current directory /
- /usr/home/studenti/st93302
- gt cd mydir / change directory /
- gt pwd
- /usr/home/studenti/st93302/mydir
6Come muoversi nel File System
- gt cd /usr/home/studenti / change dir with /
- gt pwd / with absolute path /
- /usr/home/studenti
- gt cd st93302/mydir / change dir with /
- gt pwd / with relative path /
- /usr/home/studenti/st93302/mydir
- gt cd / change to home directory /
7Come muoversi nel File System
- gt pwd
- /usr/home/studenti/st93302
- gt cd .. / change to parent directory /
- gt pwd
- /usr/home/studenti
- gt pwd
- /usr/home/studenti/st93302
- gt cd . / . is the current directory /
- gt pwd
- /usr/home/studenti/st93302
8Manipolazione dei file
- gt ls / list current directory /
- pippo pluto program.c
- gt ls /usr/home / list specified directory /
- docenti studenti tecnici tesisti
- /usr/home/studenti
- gt ls -l / list protections, owner and size /
- -rw-r--r-- st30221 lab01 125 Nov 12 1315
pippo.c - -r-xr-xr-x st30221 lab01 670 Nov 11 1010
pluto.c -
9Manipolazione dei file
- gt ls -la / list also current and parent dir /
- -rw-r--r-- st30221 lab01 81 Oct 10 2305 .
- -rw-r--r-- st30221 lab01 75 Oct 10 0912
.. - -rw-r--r-- st30221 lab01 125 Nov 12 1315
pippo.c - -r-xr-xr-x st30221 lab01 670 Nov 11 1010
pluto.c -
10Manipolazione dei file
- gt cat pippo.c / show content of file /
- include ltstdio.hgt
- main()
- int i1 0
- char c1,c2
- ...
- ....
- gt more pippo.c / show content of file in pages
- use "space" or "enter" to advance /
11Manipolazione dei file
- gt cp pluto pippo / copy pluto onto pippo /
- / old pluto if any is lost /
- gt mv pluto pippo / change name of pluto /
- / old pippo if any is lost /
- gt rm pluto pippo / remove specified files /
-
- gt mkdir new-dir / make new directory /
12Manipolazione dei file
- gt rmdir new-dir / remove new-dir /
- / only if empty /
- gt rm r new-dir / recursively remove /
- / new-dir /
- gt wc file / counts lines words, chars in file
/ - gt wc -l file / counts lines in file /
13Manipolazione dei file
- gt diff f1 f2 / lists diffs between f1 and f2 /
-
- gt grep STR file(s) / search STR in file(s) /
-
- gt file prog.c / file type /
- prova.c c program text
- gtfind DIR -name FILE -print / search FILE /
- / in DIR recursively /
14Manipolazione dei file
- gtfind DIR -name "STR" -print
- / search for file names containing STR /
- / in DIR recursively /
- gt du / disk usage (in blocks) /
15Protezione 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
16Protezione dei file in Unix
- gt ls -l pippo
- -rw-r--r-- st30221 ... ... ... pippo
- gt chmod ux pippo / allows execution to
owner / - gt ls -l pippo
- -rwxr--r-- st30221 ... ... ... pippo
17Protezione dei file in Unix
- gt ls -l pippo
- -rwxr----- st30221 ... ... ... pippo
- gt chmod gorx pippo / allows read and
execution to / - / group and others /
- gt ls -l pippo
- -rwxr-xr-x st30221 ... ... ... pippo
18Protezione dei file in Unix
- gt ls -l new-dir
- drwxrwxrwx st30221 ... ... ... new-dir
- gt chmod a-rw new-dir / forbids read and write
/ - / to everyone /
- gt ls -l new-dir
- d--x--x--x st30221 ... ... ... new-dir
19cambiamento di appartenenza dei file in Unix
gt ls -l -rw-r--r-- st30221 lab01 125 Nov 12
1315 pippo.c -r-xr-xr-x st30221 lab01 670
Nov 11 1010 pluto.c gt chown st96932 pippo.c
/change owner of file / gt ls
-l -rw-r--r-- st96932 lab01 125 Nov 12 1315
pippo.c -r-xr-xr-x st30221 lab01 670 Nov 11
1010 pluto.c
20Gestione dei processi in Unix
- gt ps / show Process Status of terminal /
- PID TT STAT TIME COMMAND
- p0 S 001 -csh (csh)
- p0 R 000 ps
- gt ps agx /shows all processes /
- gt ctrl-C / kills a running process /
- gt ctrl-Z / suspends a running process /
21Foreground e Background
Normalmente, quando lanciate un comando o un
eseguibile, il controllo del terminale (il
prompt) ritorna solo alla terminazione del
processo corrispondente mypromptgt sleep 10
echo "ciao!" / waits 10 seconds / ... for 10
seconds nothing happens ... ... no other
commands can be run until 10 sec.
expire ciao! mypromptgt Questa e' l'esecuzione dei
processi in foreground
22Foreground e Background
Tuttavia e' possibile lanciare un comando o un
programma, e mentre il processo relativo e' in
esecuzione eseguire altri comandi/programmi mypr
omptgt sleep 10 echo "ciao!" / waits 10
seconds mypromptgt date Mon Nov 12 163113
2001 mypromptgt cp pippo pluto mypromptgt ... /
and 10 seconds later / ciao! Questa e'
l'esecuzione dei processi in background
23 Foreground e Background
gt ctrl-Z / suspends a foreground running
process / gt fg / resume in foreground
a suspended process / gt bg / resume
in background a suspended process / gt
jobs / shows background processes /
24Uccisione di un processo in Unix
- gt ps / show Process Status of terminal /
- PID TT STAT TIME COMMAND
- p0 S 001 -csh (csh)
- p0 R 050 a.out
- 1234 p0 R 000 ps
- gt kill 1419 / kill the specified process /
- gt kill -9 1419 / 1419 cannot ignore kill /
- SIGKILL
25Alcuni metacaratteri C-Shell
gt !! / re-executes last issued command / gt
!w / re-executes last command starting wit
h "w" / gt ls .c / asterisk subsitute for
everything / gt ls gt pippo / output
redirection / gt cat pippo prova.c prog.c
26Alcuni metacaratteri C-Shell
\METACHAR / escape for METACHARS / gt cp
pippo ltgt / error of redirection / gt cp
pippo \lt\gt / creates a file called ltgt /
27File speciali C-Shell
.login / configures login session / .cshrc
/ set aliases, seraching paths, ... / alias
ll "ls -l" / renames "ls -l" as ll / gt source
.cshrc / re-read .cshrc useful if searching
paths are changed /
28File speciali C-Shell
- .history / remembers last issued commands /
- gt history n / shows last n issued commands
/ - ls
- date
- vi pippo.c
- lpr pippo.c
- pwd
- gt !44 / re-issues command n. 44 /
- lpr pippo.c
29File speciali C-Shell
- gt history n / shows last n issued commands
/ - ls mydir
- date
- vi pippo.c
- gt !ls / re-issues last "ls" command /
- ls mydir
- gt cd ! / ! is the last arg. of previous
command / - cd mydir
30Text 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.
31Text 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 - gt vi prova.c / creates or open prova.c /
- quando editate un file, inizialmente siete in
modalita' - COMANDO
32Text 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 /
33Text 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 /
34Text 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 /
35Text 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
/
36Text 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.
37Text 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 /
38Text 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 /
39Text 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 /
40Text editor "vi"
passaggio dal modo "INSERZIONE"al modo
"COMANDO" ltescgt In ogni momento, per passare
dalla modalita' INSERZIONE a quella di comando,
basta digitare il tasto ESCAPE.
41Uso del compilatore C
gt gcc file.c / creates an executable program
called a.out / gta.out / runs a.out
/ gt gcc file.c -o myprogram / creates an
executable called myprogram /