Cursul #5
Interfața în linia de comandă
1
It was a mistake to think that GUIs ever would, could, or even should, eliminate CLIs.
Jeffrey Snover (Architect of Windows PowerShell)
2
Suport de curs
Capitolul 7 – Interfața în linia de comandă
3
Utilizatorul și sistemul de operare
4
hardware
sistem de operare
app1
app2
app3
Shell-ul
5
hardware
sistem de operare
app1
app2
app3
shell
Shell și proces
6
Shell GUI vs CLI
7
Interfețe în linia de comandă
8
De ce CLI?
9
Funcționare CLI
10
Shell CLI
11
Bash
12
Funcționare shell
13
Foreground și background
14
Foreground și background (2)
15
Shell și terminal
16
Funcționalități terminal
17
Funcționalități shell
18
Caractere speciale în shell
19
Globbing
ana@host:~/code/tests$ ls
Makefile endian.c struct_bit struct_bit.o tcp_new_sock.c
endian endian.o struct_bit.c tcp_new_sock tcp_new_sock.o
ana@host:~/code/tests$ ls *.c
endian.c struct_bit.c tcp_new_sock.c
ana@host:~/code/tests$ ls end?an.c
endian.c
ana@host:~/code/tests$ ls [a-s]*.c
endian.c struct_bit.c
ana@host:~/code/tests$ ls *.{c,o}
endian.c endian.o struct_bit.c struct_bit.o tcp_new_sock.c tcp_new_sock.o
20
Escapări
ana@host:/tmp/uso$ ls -l
total 0
-rw-r--r-- 1 ana ana 0 2007-11-18 00:14 alfa beta.txt
-rw-r--r-- 1 ana ana 0 2007-11-18 00:14 d.txt
ana@host:/tmp/uso$ ls alfa beta.txt
ls: alfa: No such file or directory
ls: beta.txt: No such file or directory
ana@host:/tmp/uso$ ls "alfa beta.txt"
alfa beta.txt
ana@host:/tmp/uso$ ls 'alfa beta.txt'
alfa beta.txt
ana@host:/tmp/uso$ ls alfa\ beta.txt
alfa beta.txt
ana@host:/tmp/uso$ echo $a
4
ana@host:/tmp/uso$ echo "$a"
4
ana@host:/tmp/uso$ echo \$a
$a
ana@host:/tmp/uso$ echo '$a'
$a
21
Expandări
ana@host:-$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/PacketTracer5
ana@host:~/tmp$ touch $(seq -f "file-%02g.txt" 1 20)
ana@host:~$ ls
file-01.txt file-03.txt file-05.txt file-07.txt file-09.txt file-11.txt file-13.txt [...]
file-02.txt file-04.txt file-06.txt file-08.txt file-10.txt file-12.txt file-14.txt [...]
ana@host:~$ a=3
ana@host:~$ ((a++))
ana@host:~$ b=$((a+1))
ana@host:~$ echo $b
5
22
Redirectări
23
Înlănțuirea comenzilor
ana@host:~$ svn log | less
root@asgard:~# apt-get update ; apt-get upgrade ; apt-get dist-upgrade
ana@host:~$ id ana &> /dev/null && echo "da" || echo "nu"
da
ana@host:~$ id atilla &> /dev/null && echo "da" || echo "nu"
nu
24
One linere
25
Filtre de text
26
cat, tac, rev, nl
27
head, tail
28
cut, tr
29
sort, uniq, wc
30
Exemplu
31
grep
32
Expresii regulate
33
Expresii regulate
[_a-zA-Z][_0-9a-zA-Z]*: nume de variabilă/funcție
07[:digit:]\{8\}: număr de telefon
[:upper:][:alpha:]+: numele unei persoane
[:digit:]\{2\}\.(pdf|png|svg): nume fișiere din două cifre și diferite extensii
([01][:digit:]|2[0-3]):[0-5][:digit:]: timp în ore și minute
^[:upper:]\{1,10\}$: linii conținând maxim 10 majuscule
34
Windows Power Shell
35
Resurse utile
36
Unix Power Tools
37
Rob Pike
38
Amazon
39
Cuvinte cheie
40