Ls Comando
Con il comando ls (list) si ottiene l'elenco dei file (ma non il contenuto).
ESEMPIO:
$ ls
bin boot dev etc home initrd.img initrd.img.old lib lib64 libx32 lost+found media mnt opt proc root run sbin srv sys tmp usr var vmlinuz vmlinuz.old
I file vengono ordinati in automatico dal sistema in ordine alfabetico.
Il comando ls, come la maggior parte dei comandi, prevede delle opzioni che consentono di modificarne il comportamento di default, queste opzioni vanno inserite sulla stessa riga del comando dopo il comando, generalmente sono precedute dal segno meno.
Le opzioni sono costituite da una singola lettera che ne sintetizza il significato, per esempio se diamo l'opzione -l, si ottiene un elenco articolato (l sta per "long") che fornisce varie informazioni relative a ciascun file.
ESEMPIO:
$ ls -l
totale 60
lrwxrwxrwx 1 root root 7 mag 2 01:28 bin -> usr/bin
drwxr-xr-x 3 root root 4096 mag 2 01:48 boot
drwxr-xr-x 16 root root 3140 mag 2 03:21 dev
drwxr-xr-x 70 root root 4096 mag 2 03:21 etc
drwxr-xr-x 3 root root 4096 mag 2 01:49 home
lrwxrwxrwx 1 root root 33 mag 2 01:32 initrd.img -> boot/initrd.img-4.19.0-16-686-pae
lrwxrwxrwx 1 root root 33 mag 2 01:32 initrd.img.old -> boot/initrd.img-4.19.0-16-686-pae
lrwxrwxrwx 1 root root 7 mag 2 01:28 lib -> usr/lib
lrwxrwxrwx 1 root root 9 mag 2 01:28 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 10 mag 2 01:28 libx32 -> usr/libx32
drwx------ 2 root root 16384 mag 2 01:27 lost+found
drwxr-xr-x 3 root root 4096 mag 2 01:31 media
drwxr-xr-x 2 root root 4096 mag 2 01:28 mnt
drwxr-xr-x 2 root root 4096 mag 2 01:28 opt
dr-xr-xr-x 120 root root 0 gen 1 2003 proc
drwx------ 2 root root 4096 mag 2 01:28 root
drwxr-xr-x 16 root root 500 mag 16 00:52 run
lrwxrwxrwx 1 root root 8 mag 2 01:28 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 mag 2 01:28 srv
dr-xr-xr-x 13 root root 0 gen 1 2003 sys
drwxrwxrwt 8 root root 4096 mag 16 00:42 tmp
drwxr-xr-x 12 root root 4096 mag 2 01:28 usr
drwxr-xr-x 11 root root 4096 mag 2 01:28 var
lrwxrwxrwx 1 root root 30 mag 2 01:32 vmlinuz -> boot/vmlinuz-4.19.0-16-686-pae
lrwxrwxrwx 1 root root 30 mag 2 01:32 vmlinuz.old -> boot/vmlinuz-4.19.0-16-686-pae
Se diamo il comando ls -t, vogliamo che i file siano ordinati in ordine di tempo (quindi t, sta per time).
ESEMPIO:
$ ls -t
sys run tmp etc dev home boot initrd.img initrd.img.old vmlinuz vmlinuz.old media usr var opt srv mnt root libx32 lib64 lib sbin bin lost+found proc
Con l'opzione -a è possibile visualizzare anche i file nascosti.
ESEMPIO:
$ la -a
. .. .bash_history .bash_logout .bashrc .profile
Le opzioni possono essere utilizzate anche concatenate esempio ls -lt
Altro tipo di concatenamento esempio ls -l -t
ESEMPIO:
$ ls -lt
totale 60
dr-xr-xr-x 13 root root 0 mag 16 02:03 sys
drwxr-xr-x 16 root root 500 mag 16 00:52 run
drwxrwxrwt 8 root root 4096 mag 16 00:42 tmp
drwxr-xr-x 70 root root 4096 mag 2 03:21 etc
drwxr-xr-x 16 root root 3140 mag 2 03:21 dev
drwxr-xr-x 3 root root 4096 mag 2 01:49 home
drwxr-xr-x 3 root root 4096 mag 2 01:48 boot
lrwxrwxrwx 1 root root 33 mag 2 01:32 initrd.img -> boot/initrd.img-4.19.0-16-686-pae
lrwxrwxrwx 1 root root 33 mag 2 01:32 initrd.img.old -> boot/initrd.img-4.19.0-16-686-pae
lrwxrwxrwx 1 root root 30 mag 2 01:32 vmlinuz -> boot/vmlinuz-4.19.0-16-686-pae
lrwxrwxrwx 1 root root 30 mag 2 01:32 vmlinuz.old -> boot/vmlinuz-4.19.0-16-686-pae
drwxr-xr-x 3 root root 4096 mag 2 01:31 media
drwxr-xr-x 12 root root 4096 mag 2 01:28 usr
drwxr-xr-x 11 root root 4096 mag 2 01:28 var
drwxr-xr-x 2 root root 4096 mag 2 01:28 opt
drwxr-xr-x 2 root root 4096 mag 2 01:28 srv
drwxr-xr-x 2 root root 4096 mag 2 01:28 mnt
drwx------ 2 root root 4096 mag 2 01:28 root
lrwxrwxrwx 1 root root 10 mag 2 01:28 libx32 -> usr/libx32
lrwxrwxrwx 1 root root 9 mag 2 01:28 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 7 mag 2 01:28 lib -> usr/lib
lrwxrwxrwx 1 root root 8 mag 2 01:28 sbin -> usr/sbin
lrwxrwxrwx 1 root root 7 mag 2 01:28 bin -> usr/bin
drwx------ 2 root root 16384 mag 2 01:27 lost+found
dr-xr-xr-x 120 root root 0 gen 1 2003 proc
Per maggiori INFO fare riferimento al manuale digitando da terminale man ls.