diff --git a/TerminaleIssue/README.md b/TerminaleIssue/README.md new file mode 100644 index 0000000..f7e5c31 --- /dev/null +++ b/TerminaleIssue/README.md @@ -0,0 +1 @@ +Per consultare l'elenco dei comandi del terminale basta entrare nella cartella "TerminaleIssue" ed eseguire il file "print_cheatshit.sh" diff --git a/TerminaleIssue/cheatsheetTerm1.md b/TerminaleIssue/cheatsheetTerm1.md new file mode 100644 index 0000000..f087854 --- /dev/null +++ b/TerminaleIssue/cheatsheetTerm1.md @@ -0,0 +1,138 @@ +### Elenca i file + +```sh +ls /path/to/directory +``` + +### Entrare in una cartella + +```sh +cd /path/to/directory +``` + +### Uscire da una cartella + +```sh +cd .. +``` + +### Creare una cartella + +```sh +mkdir /path/to/new_directory +``` + +### Creare file + +```sh +touch /path/to/new_file.txt +``` + +### Controllare di che tipo è un file + +```sh +file /path/to/executable +``` + +### Copiare file + +```sh +cp /path/to/source_file.txt /path/to/destination_directory/ +``` + +### Spostare file + +```sh +mv /path/to/source_file.txt /path/to/destination_directory/ +``` + +### Rinominare file + +```sh +mv /path/to/old_name.txt /path/to/new_name.txt +``` + +### Eliminare file + +```sh +rm /path/to/file_to_delete.txt +``` + +### Copiare una cartella + +```sh +cp -r /path/to/source_folder /path/to/destination_folder/ +``` + +### Manuale di un comando + +```sh +man ls +``` + +### Leggere un file di testo + +```sh +less /path/to/text_file.txt +``` + +### Nano e Vim + +```sh +nano /path/to/file.txt +vim /path/to/another_file.txt +``` + +### Contare caratteri + +```sh +wc -l /path/to/file.txt +``` + +### Ricerca di una stringa + +```sh +grep "string" /path/to/file.txt +``` + +### Concatenazione o lettura + +```sh +cat /path/to/file.txt +``` + +### Testa e coda + +```sh +head /path/to/log_file.txt +tail -f /path/to/another_log.log +``` + +### Wildcard + +```sh +cp *.txt /path/to/destination/ +ls -d dir* +cat file?.txt +cat *.log +``` + +### Cambiare owner e group + +```sh +chmod 755 /path/to/script.sh +chown user:group /path/to/file.txt +chgrp group /path/to/file.txt +``` + +### Pipe + +```sh +ls /bin | less +``` + +### Ridezione su file + +```sh +comando > /path/to/output_file.txt +``` diff --git a/TerminaleIssue/cheatsheetTerm2.md b/TerminaleIssue/cheatsheetTerm2.md new file mode 100644 index 0000000..851a2ae --- /dev/null +++ b/TerminaleIssue/cheatsheetTerm2.md @@ -0,0 +1,104 @@ +### Slide della scorsa volta + +[main.pdf](https://risorse.vercel.app/lab/2025/terminale-1/main.pdf) + +# STDIO e ridirezioni + +## Output + +Normale output di un comando, può essere visto come un file e usato su pipe e ridirezione. `>` distruttiva, `>>` appende in fondo al file. + +```bash +comando > /path/to/output_file.txt +``` + +## Error + +```bash +comando_che_genera_errore > /path/to/output.txt +``` + +Il file `output.txt` viene creato (l’esecuzione non si ferma all’errore) ma `output.txt` non conterrà l’errore del comando perché non è `stdout`. + +```bash +comando_che_genera_errore > /path/to/output_and_error.txt 2>&1 +``` + +Ridirezionare lo `stderr` sullo stdout: `2>&1` . Non mostra messaggio di errore e ora `output_and_error.txt` contiene l’errore del comando. + +```bash +comando_che_genera_errore > /path/to/output.txt 2> /path/to/error_file.txt +``` + +Crea un file di nome `error_file.txt` e `output.txt` è vuoto. Ha preso `2> /path/to/error_file.txt` come: prendi lo `stderr` e mettilo nel file specificato. + +```bash +comando_che_genera_errore > /path/to/output.txt 2>/dev/null +``` + +Butta tutti gli errori dentro `/dev/null` e non saranno più recuperabili. + +## Echo + +```bash +echo /path/to/*/pattern +``` + +Stampa tutti i percorsi relativi delle sottocartelle (o cartelle) che corrispondono a `pattern` all'interno di `/path/to/`. + +```bash +echo {1..10} +echo {a..z} +``` + +Stampa tutti i numeri e caratteri in mezzo ai valori definiti. + +```bash +file $(ls -d /bin/* | grep utility_name) +file $(find /path/to/binaries -name "program_name" -print) +``` + +Il primo esempio stampa informazioni sui file che corrispondono a `utility_name` tra gli eseguibili in `/bin/`. Il secondo esempio trova il percorso di un `program_name` in `/path/to/binaries` e stampa il tipo di file. Questa sintassi è necessaria per rispettare la sintassi di `file`. + +# Variabili + +```bash +set src "/path/to/source_folder" +set dest "/path/to/destination_folder" +echo "$dest" +echo "$src" +cp -r "$src" "$dest" +ls /path/to/directory +``` + +`set` copia i valori nelle variabili locali, e `cp` copia le cartelle ricorsivamente l’una dentro l’altra. + +```bash +bash -c "comando con argomenti" +``` + +Lancia un comando in una nuova shell. + +Le variabili custom vengono eliminate al riavvio del computer. + +# Shell scripting + +Per specificare che interprete usare: + +```bash +#!/bin/bash +``` + +Specifica l’interprete da usare nella prima riga del file. Dice al terminale che stiamo creando un file di scripting. Non è necessario chiamare i file di scripting `*.sh` e definire le variabili maiuscole. + +```bash +#!/bin/bash +echo "Reading programs" +PROG=$(ls -d /bin/*) +NUM=$(echo "$PROG" | grep "ca" | wc -l) +echo "Number of programs containing 'ca': $NUM" +``` + +`NUM=$(echo "$PROG" | grep "ca" | wc -l)` stampa il contenuto di `$NUM`, che conterrà il numero di programmi che iniziano con `ca`. La variabile `$NUM` rimane locale all’esecuzione dello script, non posso neanche usare `export` perché viene trasposta ai processi figli di quel nuovo terminale creato all’inizio dello script. + +`chmod +x /path/to/my_script.sh` permesso di esecuzione a user. diff --git a/TerminaleIssue/print_cheatshit.sh b/TerminaleIssue/print_cheatshit.sh new file mode 100755 index 0000000..72a32b2 --- /dev/null +++ b/TerminaleIssue/print_cheatshit.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Nome dello script: stampa_file_predefiniti.sh +# Descrizione: Stampa il contenuto di due file predefiniti che si trovano +# nella stessa cartella dello script. + +# --- 1. DEFINIZIONE DEI NOMI DEI FILE --- +# Definisci qui i nomi esatti dei file che vuoi stampare. +FILE1="cheatsheetTerm1.md" +FILE2="cheatsheetTerm2.md" +# ---------------------------------------- + +echo "Esecuzione dello script nella cartella: $(pwd)" +echo "---" + +echo "--- 📝 Contenuto di $FILE1 ---" +if [ -f "$FILE1" ]; then + # Stampa il contenuto del primo file + cat "$FILE1" +else + echo "Errore: Il file '$FILE1' non esiste in questa cartella." +fi + +echo "" # Aggiunge una riga vuota per separazione + +echo "--- 📝 Contenuto di $FILE2 ---" +if [ -f "$FILE2" ]; then + # Stampa il contenuto del secondo file + cat "$FILE2" +else + echo "Errore: Il file '$FILE2' non esiste in questa cartella." +fi + +echo "--- Fine dello script ---" diff --git "a/inpi\303\271" "b/inpi\303\271" new file mode 100644 index 0000000..74ecf54 --- /dev/null +++ "b/inpi\303\271" @@ -0,0 +1 @@ +inpiù