Link to home
Create AccountLog in
Avatar of jjc_mn
jjc_mn

asked on

Count number of files in directory and subdirectory

I'm trying to count the number of files in a directory and all the sub directories. The command "find . -type f | wc -l " worked in a directory with a few files and sub-directories but it is not working in a directory with lots of sub-directories and files. It just comes back in a few seconds showing nothing. The slice is 100% full. Not sure if that's playing a factor.

Any other good way to count?
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jjc_mn
jjc_mn

ASKER

du -k  doesn't get the hidden files and it includes the directories. I just want a file count

"find /blah -type f " doesn't work any better than "cd /blah; find . -type f" It returns files in the current directory but not sub-directories. I didn't realize that at first because there were no files in the the current directory until I just put one there. It see that and the quits.

I did discover one other factor that may be important. The directory (and sub-dirs) are on a NFS mount. The mount is a equalogic san. Does find work different on NFS mounts?
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
That explains it... all Unix filesystems and windows filesystems have a . & .. entry as a link to self & parent directory.
Non unix native filesystems (f.e. ODS-2, ODS-5 on OpenVMS, FAT top level directory, ISO-9660 (CD/DVD format) dont have these... That would not be a problem if find actualy checked for those.
To speadup operations it counts the entries in directory and substract 2. If there are less then 2 entries in a directory it will asumme the directory is empty and that's it.

The RR- extenstions supply a fake . & .. but without them the ISO-9660 fs doesn't have those . & .. references.

ls has a likewise quirk. To prevent unneeded printing any file starting with . (. & ..) is suppressed (unless -a is given).
this had the side effect that any file starting with . is not printed in a regular ls command.  Hence the 'hidden' files in Unix.
The fact that the directory is on CD is a mayor factor in getting the solution to this question.