Different answers when trying to learn file numbers

I wanted to discover the number of files on my system. I found on the Web the suggestion that the way to do so was to type in the Terminal, as user, "find / \! -type -d | wc -l" and then press "Enter". I did that. The names of quite a few files appeared on the screen, each with the words "Permission denied" after it, and then, ultimately, the number 153,406. I decided to issue the command as root instead, to see what happened. No file names appeared on the screen as they had before. I just got the number 154,821. That was 1,415 more than earlier, though the number of filenames which had appeared with "Permission denied" the first time round was nowhere near as many as 1,415. I next edited my sudoers file, so that, as user, I didn't need to enter a password in order to run "find". I then typed, as user, "sudo", followed by the command I'd typed twice before. That time, I got the number 154,722. Can anyone explain to me why I've been getting the different results that I have?

Try excluding /proc and /sys and see what you get. Regards Leslie Katz wrote:
I wanted to discover the number of files on my system.
I found on the Web the suggestion that the way to do so was to type in the Terminal, as user, "find / \! -type -d | wc -l" and then press "Enter".
I did that. The names of quite a few files appeared on the screen, each with the words "Permission denied" after it, and then, ultimately, the number 153,406.
I decided to issue the command as root instead, to see what happened.
No file names appeared on the screen as they had before. I just got the number 154,821. That was 1,415 more than earlier, though the number of filenames which had appeared with "Permission denied" the first time round was nowhere near as many as 1,415.
I next edited my sudoers file, so that, as user, I didn't need to enter a password in order to run "find".
I then typed, as user, "sudo", followed by the command I'd typed twice before. That time, I got the number 154,722.
Can anyone explain to me why I've been getting the different results that I have?
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

* Leslie Katz <lesliek(a)ozemail.com.au> [2005-12-13 07:45]:
That was 1,415 more than earlier, though the number of filenames which had appeared with "Permission denied" the first time round was nowhere near as many as 1,415.
When find(1) fails to descend into a directory because it does not have sufficient permissions, it can’t and won’t give you errors for each of the files and directories beneath. That most likely explains this difference.
I then typed, as user, "sudo", followed by the command I'd typed twice before. That time, I got the number 154,722.
This difference is small; about 100 files between the two complete totals. It’s probably caused by /proc, /sys and/or other pseudofilesystems, as Oliver said. Btw, I suggest something along the lines of find / \! -type d -printf . | wc -c instead; it’s a smidgen more efficient and robust. Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>
participants (3)
-
A. Pagaltzis
-
Leslie Katz
-
Oliver Jones