So I needed to find the number of files in a directory recursively. I found a great way to figure that out on Linux that has helped me a couple times now. I definitely need to remember it…anyway here is is:

find /my/directory -type f |wc -l

If you need to find the number of directories recursively then do:

find /my/directory -type d | wc -l

Find will just print out all the files it finds. It you tell find a type to find it will only print files of that type (f for file, d for directory). wc will just count the number of lines in the output

Tags: