This shows you the differences between two versions of the page.
uso:cursuri:curs-05 [2020/11/08 22:22] ebru.resul [Expandări] |
uso:cursuri:curs-05 [2022/10/31 22:54] (current) sergiu.weisz |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Curs 05 - Interfața în linia de comandă ======= | ====== Curs 05 - Interfața în linia de comandă ======= | ||
- | * [[https://drive.google.com/file/d/1eVXc6NjK9ZT_e8sXLjRsYbpM0cXbOvAF/view?usp=sharing|Slide-uri curs]] | + | * [[https://docs.google.com/presentation/d/1Dk4gnDZd3TefbtyG3i4qSoO7YoXZOP5q/edit?usp=sharing&ouid=108131427433094834232&rtpof=true&sd=true|Slide-uri curs]] |
- | * [[https://drive.google.com/file/d/1oKwswVWD8_mr-7JBXPWLkYp4nH3PIOi3/view?usp=sharing|Handout 3on1 and notes space]] | + | |
- | * [[https://drive.google.com/file/d/1NKTEnApsjX5zQd7w0sOZ6Z8y4lUyv-UR/view?usp=sharing|Handout 6on1]] | + | |
* **Cuvinte cheie**: interfață, GUI, CLI, prompt, comandă, argumente, command completion, istoric de comenzi, shell, terminal, documentare, libreadline, ''>'', ''<'', ''&'', ''|'', ''||'', ''&&'', '';'', ''%%"%%'', %%'%%, ''\'', ''$'', one liner, variabile, variabile de mediu, escaping, expandare, globbing | * **Cuvinte cheie**: interfață, GUI, CLI, prompt, comandă, argumente, command completion, istoric de comenzi, shell, terminal, documentare, libreadline, ''>'', ''<'', ''&'', ''|'', ''||'', ''&&'', '';'', ''%%"%%'', %%'%%, ''\'', ''$'', one liner, variabile, variabile de mediu, escaping, expandare, globbing | ||
- | * [[http://elf.cs.pub.ro/uso/res/carte/uso_cap-07-cli.pdf|Capitolul 7 din carte: Interfața în linia de comandă]] | + | * **Suport de curs** |
- | * **Suport de vechi** | + | * [[https://github.com/systems-cs-pub-ro/carte-uso/releases | Utilizarea sistemelor de operare]] |
- | * [[http://books.google.com/books?id=_JFGzyRxQGcC | Introducere în sisteme de operare]] | + | * Secțiunea 7 - Interfata in linia de comanda |
- | * [[http://books.google.com/books?id=_JFGzyRxQGcC&pg=PA36 | Capitolul 12 - Shell scripting]] | + | |
- | * Secțiunile 12.1, 12.2, 12.6, 12.75 | + | |
+ | <HTML> | ||
+ | <center> | ||
+ | <iframe src="https://docs.google.com/presentation/d/e/2PACX-1vSgCQrUZIoJoRMvmJZZzYrrPCpdW2Id2_Rjv0rec-IKsKx0tkpXc8jnPS5NLCSq1g/embed?start=false&loop=false&delayms=3000" frameborder="0" width="480" height="389" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe> | ||
+ | </center> | ||
+ | </HTML> | ||
/* | /* | ||
Line 38: | Line 39: | ||
==== Variabila PATH ==== | ==== Variabila PATH ==== | ||
- | Daca rulati in terminal comanda: | + | Dacă rulați în terminal comanda: |
<code>echo $PATH</code> | <code>echo $PATH</code> | ||
- | Veti vedea o lista de directoare de genul: | + | Veți vedea o listă de directoare de genul: |
<code>/home/student/.local/share/umake/bin:/home/student/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin</code> | <code>/home/student/.local/share/umake/bin:/home/student/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin</code> | ||
- | Daca puneti un executabil in oricare din aceste directoare, nu mai este nevoie sa setati calea catre executabil si puteti sa il rulati direct ca o comanda, folosind numele executabilului. | + | Dacă puneți un executabil în oricare din aceste directoare, nu mai este nevoie să setați calea către executabil și puteți să îl rulați direct ca o comandă, folosind numele executabilului. |
==== Globbing ==== | ==== Globbing ==== | ||
Line 59: | Line 60: | ||
</code> | </code> | ||
- | Mai sus avem cateva exemple de rulare a comenzii ls impreuna cu expresii regulate. | + | Mai sus avem câteva exemple de rulare a comenzii ls impreună cu expresii regulate. |
Ce reprezintă fiecare operator? | Ce reprezintă fiecare operator? | ||
Line 115: | Line 116: | ||
</code> | </code> | ||
- | <note>Pentru ca un caracter special sa fie utilizat in bash, el trebuie sa fie escapat.</note> | + | <note>Pentru ca un caracter special să fie utilizat ca un caracter obișnuit în bash, el trebuie să fie escapat.</note> |
==== Expandări ==== | ==== Expandări ==== | ||
Line 204: | Line 205: | ||
<note> | <note> | ||
- | * cat → afiseaza continutul fisierului | + | * cat → afișeaza conținutul fișierului |
- | * tac → afiseaza continutul fisierului in ordine inversa a liniilor | + | * tac → afișeaza conținutul fișierului în ordinea inversă a liniilor |
- | * rev → afiseaza liniile inversate (primul element de pe linie devine ultimul) | + | * rev → afișeaza liniile inversate (primul element de pe linie devine ultimul) |
- | * nl → afiseaza numarul liniei | + | * nl → afișeaza numărul liniei |
</note> | </note> | ||
Line 228: | Line 229: | ||
<note> | <note> | ||
+ | * head -n 2 → afișează primele 2 linii din fisier | ||
+ | * tail -n 2 → afișează ultimele 2 linii din fisier | ||
</note> | </note> | ||
+ | ==== sort, uniq și wc ==== | ||
+ | <code> | ||
+ | student@myPc:~/USO/test/files$ cat test.txt | ||
+ | Ana are mere | ||
+ | Ana are mere 2 | ||
+ | Ana are mere 3 | ||
+ | Maria are pere | ||
+ | Ana are mere | ||
+ | student@myPc:~/USO/test/files$ sort test.txt | ||
+ | Ana are mere | ||
+ | Ana are mere | ||
+ | Ana are mere 2 | ||
+ | Ana are mere 3 | ||
+ | Maria are pere | ||
+ | student@myPc:~/USO/test/files$ sort -r -n test.txt | ||
+ | Maria are pere | ||
+ | Ana are mere 3 | ||
+ | Ana are mere 2 | ||
+ | Ana are mere | ||
+ | Ana are mere | ||
+ | student@myPc:~/USO/test/files$ wc test.txt | ||
+ | 5 17 71 test.txt | ||
+ | student@myPc:~/USO/test/files$ wc -c test.txt | ||
+ | 71 test.txt | ||
+ | student@myPc:~/USO/test/files$ wc -l test.txt | ||
+ | 5 test.txt | ||
+ | student@myPc:~/USO/test/files$ sort test.txt > test22.txt | ||
+ | student@myPc:~/USO/test/files$ cat test22.txt | ||
+ | Ana are mere | ||
+ | Ana are mere | ||
+ | Ana are mere 2 | ||
+ | Ana are mere 3 | ||
+ | Maria are pere | ||
+ | student@myPc:~/USO/test/files$ uniq test22.txt | ||
+ | Ana are mere | ||
+ | Ana are mere 2 | ||
+ | Ana are mere 3 | ||
+ | Maria are pere | ||
+ | </code> | ||
+ | <note> | ||
+ | * sort → sortează intrările | ||
+ | * uniq → elimină duplicatele din fișier | ||
+ | * wc → numară elementele din fisier | ||
+ | </note> | ||
+ | ==== cut și tr ==== | ||
+ | |||
+ | <code>student@myPc:~/USO/test$ ls -l | ||
+ | total 4 | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:41 'ana are mere.txt' | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:18 endian.c | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:18 endian.o | ||
+ | drwxr-xr-x 2 student student 4096 nov 8 18:36 files | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 hello | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 hello.c | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 Makefile | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:01 socket.c | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 struct.c | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:01 struct.o | ||
+ | student@myPc:~/USO/test$ ls -l | tr -d '.' | ||
+ | total 4 | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:41 ana are meretxt | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:18 endianc | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:18 endiano | ||
+ | drwxr-xr-x 2 student student 4096 nov 8 18:36 files | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 hello | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 helloc | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 Makefile | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:01 socketc | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:00 structc | ||
+ | -rw-r--r-- 1 student student 0 nov 8 17:01 structo | ||
+ | student@myPc:~/USO/test$ ls -l | tr -d ' ' | ||
+ | total4 | ||
+ | -rw-r--r--1studentstudent0nov817:41anaaremere.txt | ||
+ | -rw-r--r--1studentstudent0nov817:18endian.c | ||
+ | -rw-r--r--1studentstudent0nov817:18endian.o | ||
+ | drwxr-xr-x2studentstudent4096nov818:36files | ||
+ | -rw-r--r--1studentstudent0nov817:00hello | ||
+ | -rw-r--r--1studentstudent0nov817:00hello.c | ||
+ | -rw-r--r--1studentstudent0nov817:00Makefile | ||
+ | -rw-r--r--1studentstudent0nov817:01socket.c | ||
+ | -rw-r--r--1studentstudent0nov817:00struct.c | ||
+ | -rw-r--r--1studentstudent0nov817:01struct.o | ||
+ | student@myPc:~/USO/test$ ls -l | tr -d '-' | ||
+ | total 4 | ||
+ | rwrr 1 student student 0 nov 8 17:41 ana are mere.txt | ||
+ | rwrr 1 student student 0 nov 8 17:18 endian.c | ||
+ | rwrr 1 student student 0 nov 8 17:18 endian.o | ||
+ | drwxrxrx 2 student student 4096 nov 8 18:36 files | ||
+ | rwrr 1 student student 0 nov 8 17:00 hello | ||
+ | rwrr 1 student student 0 nov 8 17:00 hello.c | ||
+ | rwrr 1 student student 0 nov 8 17:00 Makefile | ||
+ | rwrr 1 student student 0 nov 8 17:01 socket.c | ||
+ | rwrr 1 student student 0 nov 8 17:00 struct.c | ||
+ | rwrr 1 student student 0 nov 8 17:01 struct.o | ||
+ | </code> | ||
+ | |||
+ | <code>student@myPc:~/USO/test/files$ cat test.txt | ||
+ | Ana are mere | ||
+ | Ana are mere 2 | ||
+ | Ana are mere 3 | ||
+ | Maria are pere | ||
+ | Ana are mere | ||
+ | student@myPc:~/USO/test/files$ cat test.txt | cut -d' ' -f1 | ||
+ | Ana | ||
+ | Ana | ||
+ | Ana | ||
+ | Maria | ||
+ | Ana | ||
+ | student@myPc:~/USO/test/files$ cat test.txt | cut -d' ' -f1,3 | ||
+ | Ana mere | ||
+ | Ana mere | ||
+ | Ana mere | ||
+ | Maria pere | ||
+ | Ana mere | ||
+ | </code> | ||
+ | |||
+ | <note> | ||
+ | * tr → elimină caractere | ||
+ | * cut → afișeaza doar liniile pe care le dăm de la tastatură | ||
+ | </note> |