0

in Microsoft Windows you can right click on a folder for Properties and it will report Contains # files and # folders

Is there a way to do this in linux on the command line?

I want to know the total number of files and the total number of folders under a given folder as well as within any and all subfolders from that starting folder.

ron
  • 6,575

1 Answers1

0

The total number of directories under the directory called dir (including dir itself):

find dir -type d -exec echo x \; | wc -l

This locates any directory in or under dir (and dir itself) and outputs an x for each. The the number of lines outputted is then counted with wc -l.

Doing it this way allows us to count also names containing newlines correctly.

The total number of non-directories (files) under dir:

find dir ! -type d -exec echo x \; | wc -l

On a system using GNU find (such as Linux), this may be sped up by replacing -exec echo x \; with -printf 'x\n'.

With the tree command, if available:

tree -a dir | tail -n 1
Kusalananda
  • 333,661