217
72
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?
Not exactly what you're looking for, but to get a very quick grand total, if your
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 – 2010-11-13T09:44:06.227By the way, this is a different, but closely related problem (counting all the directories on a drive) and solution: http://superuser.com/questions/129088/how-can-i-count-the-number-of-folders-in-a-drive-using-linux
– Amanda – 2012-06-20T14:05:08.997