Possible Duplicate:
How can I count the number of folders in a drive using Linux?
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/
If I pass in /home
, I would like for it to return four files. Or, bonus points if it returns four files and two directories. Basically, I want the equivalent of right-clicking a folder on Windows and selecting properties and seeing how many files/folders are contained in that folder.
How can I most easily do this? I have a solution involving a Python script I wrote, but why isn't this as easy as running ls | wc
or similar?
locate
database is up to date:locate /some/path | wc -l
(or on my Mac:locate -c /some/path
). But: this will also count files in/this/other/path/with/some/path
, and will count the folders themselves. – Arjan Nov 13 '10 at 9:44