Get in touch

Send an email to: lammers@gmail.com.
Or find me online at: Github, X

Count the files in a directory

To count the files in a directory we first need to list them and then pipe the result in wc. Note that the -1 flag (That is one not the l character) is used to make sure that the output is one entry per line.

$ ls -1 <directory> | wc -l

# To also include hidden files
$ ls -1a <directory> | wc -l

Or to recursively get all files including the subdirectories we can use find

$ find <directory> -type f | wc -l