How to count files in a directory in linux

13 Giugno 2013 di In: Sistemistico

In order to count files in a directory in linux, the command to execute is:

ls -l [directory] | grep ^- | wc -l

ls -l gets you a detailed list of the directory content
grep ^- filters the output of the first command showing all the lines beginning with –
wc -l counts lines after executing the first 2 commands

If you wanted to count only directories you can execute the following command:

ls -l [directory] | grep ^d | wc -l

Nessun commento presente