Recursively counting files in a Linux directory

If you want to count the number of files you have in a directory, including all the subdirectories from the command line:



find DIR_NAME -type f | wc -l

Notes:

Replace DIR_NAME with . to execute the command in the current folder.

You can also remove the -type f to include directories (and symlinks) in the count.

It’s possible this command will overcount if filenames can contain newline characters.

Leave a Reply

Your email address will not be published. Required fields are marked *

*