...

document

by user

on
Category: Documents
8

views

Report

Comments

Description

Transcript

document
Principali comandi del Sistema
Operativo Unix
•
•
•
•
Christian: The Unix Operating System
Redivo – Zaglia: Unix
Bourne: The Unix System
Quartiroli – Fusaro – Smareglia: Unix
1
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:
...............
2
Uso del manuale in linea
$> apropos who
who
whoami
w
- who's logged in
- display current user
- what everyone is doing
$> apropos logged
logname
w
-get the name you are using
- what everyone is doing
3
Il file system delle macchine
Unix per la didattica
/
bin
lib
home
docenti
tecnici
labgroup
...
usr
local
studenti
st343920
...
tesisti
st375409
4
Come muoversi nel File System
$> pwd
/* path to current directory */
/usr/home/studenti/st93302
$> cd mydir
/* change directory */
$> pwd
/usr/home/studenti/st93302/mydir
5
Come muoversi nel File System
$> cd /usr/home/studenti
$> pwd
/usr/home/studenti
/* change dir with */
/* with absolute path */
$> cd st93302/mydir
/* change dir with */
$> pwd
/* with relative path */
/usr/home/studenti/st93302/mydir
$> cd
/* change to home directory */
6
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
7
Manipolazione dei file
$> ls
pippo
/* list current directory */
pluto
program.c
$> ls /usr/home /* list specified directory */
docenti
studenti tecnici
tesisti
/usr/home/studenti
$> ls -l
/* list protections, owner and size */
-rw-r--r--r-xr-xr-x
st30221 lab01 125 Nov 12 13:15 pippo.c
st30221 lab01 670 Nov 11 10:10 pluto.c
8
Manipolazione dei file
$> ls -la
/* list also current and parent dir */
-rw-r--r--rw-r--r--rw-r--r--r-xr-xr-x
st30221
st30221
st30221
st30221
lab01
lab01
lab01
lab01
81
75
125
670
Oct 10 23:05 .
Oct 10 09:12 ..
Nov 12 13:15 pippo.c
Nov 11 10:10 pluto.c
9
Manipolazione dei file
$> cat pippo.c
/* show content of file */
#include <stdio.h>
main()
int i1 = 0;
char c1,c2;
...
....
$> more pippo.c /* show content of file in pages
use "space" or "enter" to advance */
10
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 */
11
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 */
12
Manipolazione dei file
$> diff f1 f2
/* lists diffs between f1 and f2 */
$> grep STR file(s)
$> file prog.c
prova.c :
/* search STR in file(s) */
/* file type */
c program text
$>find DIR -name FILE -print /* search FILE */
/* in DIR recursively */
13
Manipolazione dei file
$>find DIR -name "*STR*" -print
/* search for file names containing STR */
/* in DIR recursively */
$> du
/* disk usage (in blocks) */
14
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
15
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
16
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
17
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
18
cambiamento di appartenenza dei
file in Unix
$> ls -l
-rw-r--r--
st30221 lab01 125 Nov 12 13:15 pippo.c
-r-xr-xr-x
st30221 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-x
st30221 lab01 670 Nov 11 10:10 pluto.c
19
Gestione dei processi in Unix
$> ps
/* show Process Status of terminal */
PID TT
STAT
TIME
COMMAND
1418 p0
S
0:01
-csh (csh)
1423p0
R
0:00
ps
$> ps agx /*shows all processes */
$> ctrl-C /* kills a running process */
$> ctrl-Z /* suspends a running process */
20
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
21
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
22
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 */
23
Uccisione di un processo in Unix
$> ps
/* show Process Status of terminal */
PID TT
STAT
TIME
COMMAND
1418 p0
S
0:01
-csh (csh)
1419 p0
R
0:50
a.out
1234 p0
R
0:00
ps
$> kill 1419
/* kill the specified process */
$> kill -9 1419 /* 1419 cannot ignore kill */
SIGKILL
24
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
25
Alcuni metacaratteri C-Shell
\METACHAR
/* escape for METACHARS */
$> cp pippo <>
/* error of redirection */
$> cp pippo \<\>
/* creates a file called <> */
26
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 */
27
File speciali C-Shell
.history
/* remembers last issued commands */
$> history [n]
/* shows last n issued commands */
41 ls
42 date
43 vi pippo.c
44 lpr pippo.c
45 pwd
$> !44
/* re-issues command n. 44 */
lpr pippo.c
28
File speciali C-Shell
$> history [n]
/* shows last n issued commands */
41 ls mydir
42 date
43 vi pippo.c
$> !ls
/* re-issues last "ls" command */
ls mydir
$> cd !$
/* !$ is the last arg. of previous command */
cd mydir
29
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. 30
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
31
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 */
32
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 */
33
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 */
34
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 */
35
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.
36
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 */
37
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 */
38
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 */
39
Text editor "vi"
passaggio dal modo "INSERZIONE"al modo "COMANDO"
<esc>
In ogni momento, per passare dalla modalita' INSERZIONE
a quella di comando, basta digitare il tasto ESCAPE.
40
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 */
41
Fly UP