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.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
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?
Unlimited question asking, solutions, articles and more.
noci
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.
noci
The fact that the directory is on CD is a mayor factor in getting the solution to this question.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
"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?