Usare il comando dir in Linux
Quando vogliamo visualizzare il contenuto di una directory in Linux, in genere usiamo il comando ls.
Ma c'è anche il comando dir che ci permette di visualizzare il contenuto di una directory.
Vediamo qualche esempio, partendo dal fatto che se non viene indicata una directory, viene presa quella corrente di default:
$ dir
client common node_modules package.json package-lock.json README.md server
Questa visualizzazione da comunque poche info.
Possiamo ampliarlo visualizzando anche i file nascosti, ma nascondendo le directory . e .. (-A); viso che ci siamo, visualizzaziamo il tutto in modalità lista (-l):
$ dir -Al
totale 168
drwxr-xr-x 2 matte matte 4096 3 ott 15.14 client
drwxr-xr-x 3 matte matte 4096 3 ott 15.15 common
-rw-r--r-- 1 matte matte 288 3 ott 15.14 .editorconfig
-rw-r--r-- 1 matte matte 8 3 ott 15.14 .eslintignore
-rw-r--r-- 1 matte matte 27 3 ott 15.14 .eslintrc
-rw-r--r-- 1 matte matte 151 3 ott 15.14 .gitignore
drwxr-xr-x 366 matte matte 12288 3 ott 15.49 node_modules
-rw-r--r-- 1 matte matte 762 4 ott 10.55 package.json
-rw-r--r-- 1 matte matte 117398 3 ott 15.49 package-lock.json
-rw-r--r-- 1 matte matte 77 3 ott 15.14 README.md
drwxr-xr-x 3 matte matte 4096 3 ott 15.14 server
-rw-r--r-- 1 matte matte 30 3 ott 15.14 .yo-rc.json
Aggiungiamo le dimensioni in maniera più leggibile (-h):
$ dir -Alh
totale 168K
drwxr-xr-x 2 matte matte 4,0K 3 ott 15.14 client
drwxr-xr-x 3 matte matte 4,0K 3 ott 15.15 common
-rw-r--r-- 1 matte matte 288 3 ott 15.14 .editorconfig
-rw-r--r-- 1 matte matte 8 3 ott 15.14 .eslintignore
-rw-r--r-- 1 matte matte 27 3 ott 15.14 .eslintrc
-rw-r--r-- 1 matte matte 151 3 ott 15.14 .gitignore
drwxr-xr-x 366 matte matte 12K 3 ott 15.49 node_modules
-rw-r--r-- 1 matte matte 762 4 ott 10.55 package.json
-rw-r--r-- 1 matte matte 115K 3 ott 15.49 package-lock.json
-rw-r--r-- 1 matte matte 77 3 ott 15.14 README.md
drwxr-xr-x 3 matte matte 4,0K 3 ott 15.14 server
-rw-r--r-- 1 matte matte 30 3 ott 15.14 .yo-rc.json
Se vogliamo visualizzare prima le directories (--group-directories-first):
$ dir -Alh --group-directories-first
totale 168K
drwxr-xr-x 2 matte matte 4,0K 3 ott 15.14 client
drwxr-xr-x 3 matte matte 4,0K 3 ott 15.15 common
drwxr-xr-x 366 matte matte 12K 3 ott 15.49 node_modules
drwxr-xr-x 3 matte matte 4,0K 3 ott 15.14 server
-rw-r--r-- 1 matte matte 288 3 ott 15.14 .editorconfig
-rw-r--r-- 1 matte matte 8 3 ott 15.14 .eslintignore
-rw-r--r-- 1 matte matte 27 3 ott 15.14 .eslintrc
-rw-r--r-- 1 matte matte 151 3 ott 15.14 .gitignore
-rw-r--r-- 1 matte matte 762 4 ott 10.55 package.json
-rw-r--r-- 1 matte matte 115K 3 ott 15.49 package-lock.json
-rw-r--r-- 1 matte matte 77 3 ott 15.14 README.md
-rw-r--r-- 1 matte matte 30 3 ott 15.14 .yo-rc.json
In genere è la visualizzazione che usiamo nei file manager grafici.
Infine vediamo l'opzione per listare ricorsivamente le directories (-R):
$ dir -AlhR --group-directories-first
Non vi metto l'output perchè sarebbe troppo lungo.
Ovviamente ci stanno altre opzioni, come il sorting, ecc.
Enjoy!
linux ls dir
Commentami!