Log in

View Full Version : How to count all files inside a folder, its subfolder and all


Kaleva
2015-08-18, 03:40 PM
How to count all files inside a folder, its subfolder and all . The count should not include folder count

I have a really deep directory tree on my Linux box. I would like to count all of the files in that path, including all of the subdirectories.

For instance, given this directory tree:
/home/blue
/home/red
/home/dir/green
/home/dir/yellow
/home/otherDir/

Sabin
2015-08-18, 03:41 PM
find . -type f | wc -l

Explanation:
find . -type f finds all files ( -type f ) in this ( . ) directory and in all sub directories, the filenames are then printed to standard out one per line.

This is then piped | into wc (word count) the -l option tells wc to only count lines of its input.

Together they count all your files.

Quakertown
2015-08-18, 03:42 PM
Find all files under home and count them using wc. This works on linux:

find home -type f | wc -l