11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

m<br />

rm<strong>di</strong>r<br />

mk<strong>di</strong>r<br />

bash$ mv <strong>di</strong>rectory_iniziale <strong>di</strong>rectory_destinazione<br />

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

bash$ ls -lF <strong>di</strong>rectory_destinazione<br />

total 1<br />

drwxrwxr-x 2 bozo bozo 1024 May 28 19:20 <strong>di</strong>rectory_iniziale/<br />

Cancella (rimuove) uno o più file. L’opzione -f forza la cancellazione anche dei file in sola lettura.<br />

È utile per evitare l’input dell’utente in uno script.<br />

Nota: Il semplice comando rm non riesce a cancellare i file i cui nomi iniziano con un trattino.<br />

bash$ rm -bruttonome<br />

rm: invalid option -- b<br />

Try ‘rm --help’ for more information.<br />

Un modo per riuscirci è far precedere il nome del file che deve essere rimosso da punto-barra.<br />

bash$ rm ./-bruttonome<br />

Un metodo alternativo è far predere il nome del file da “ -- ”.<br />

bash$ rm -- -bruttonome<br />

Attenzione<br />

Se usato con l’opzione <strong>di</strong> ricorsività -r, il comando cancella tutti i file<br />

della <strong>di</strong>rectory corrente. Uno sbadato rm -rf * può eliminare buona parte<br />

della struttura <strong>di</strong> una <strong>di</strong>rectory.<br />

Cancella una <strong>di</strong>rectory. Affinché questo comando funzioni è necessario che la <strong>di</strong>rectory non<br />

contenga alcun file -- neanche gli “invisibili” dotfile 1 .<br />

Crea una nuova <strong>di</strong>rectory. Per esempio, mk<strong>di</strong>r -p progetto/programmi/Dicembre crea<br />

la <strong>di</strong>rectory in<strong>di</strong>cata. L’opzione -p crea automaticamente tutte le necessarie <strong>di</strong>rectory in<strong>di</strong>cate nel<br />

percorso.<br />

227

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!