Per ottenere l’ip pubblico usare il comando: wget -qO- http://ipecho.net/plain | xargs echo
Categoria:BASH
Modificare permessi a file o directory
Modificare file: find . -type f -exec chmod 644 {} \; Modificare directory: find . -type f -exec chmod 644 {} \;
Righe differenti tra due file
Per trovare le righe presenti solo in file1 nel confronto tra file1 e file2 procedere nel seguente modo: nx71@iNuvoPro% sort <file1.txt > file1.txt_sorted nx71@iNuvoPro% sort <file2.txt > file2.txt_sorted nx71@iNuvoPro% comm -23 file1.txt_sorted file2.txt_sorted 305409,28/03/2022 40854,17/01/2022
Eliminare caratteri sporchi da file
cat elenco.txt | col -b > elencoPulito.txt
Dividere una stringa in base ad un pattern
Per estrarre un singolo blocco: nx71@iNuvoPro% echo “u d t q c” | cut -f 2 -d ” “ d Per estrarre due blocchi anche non consecutivi: nx71@iNuvoPro% echo “u d t q c” | cut -f 2,3 -d ” “ d t Per estrarre una serie di blocchi consecutivi: nx71@iNuvoPro% echo “u d t …
Continua a leggere Dividere una stringa in base ad un pattern
Estrarre nome file da un path
A=”/opt/data/APPOGGIO/2021/02/26/11/46/e7b71e99-ec8c-4bc0-983a-ef5925c52790.bin”echo $A | grep -o ‘[^/]*$’e7b71e99-ec8c-4bc0-983a-ef5925c52790.bin
Variabili bash
$0 – The name of the Bash script. $1 – $9 – The first 9 arguments to the Bash script. (As mentioned above.) $# – How many arguments were passed to the Bash script. $@ – All the arguments supplied to the Bash script. $? – The exit status of the most recently run process. $$ – The process ID of …
Continua a leggere Variabili bash
Intercettare n caratteri di una stringa
var=”pippo.txt” Eliminare gli ultimi 3 caratteri: echo ${var::-3} pippo. Eliminare i primi 3 caratteri: echo ${var:3} po.txt Ottenere solo i primi 3 caratteri: echo ${var::3} pip Ottenere solo gli ultimi 3 caratteri: echo ${var: -3} txt
Convertire case nomi file
Per cambiare il case dei nomi dei file usare i seguenti comandi: Da maiuscolo a minuscolo: for nomefile in $(ls <nome del file>); do mv $nomefile $(echo $nomefile | tr “[:upper:]” “[:lower:]”); done Da minuscolo a maiuscolo: for nomefile in $(ls <nome del file>); do mv $nomefile $(echo $nomefile | tr “[:lower:]” “[:upper:]”); done
Modificare stringa in più file
Per modificare una stringa cercandola in tutti i file presenti in una cartella o in una struttura di cartelle usare il comando: