0

I'm trying to figure out why find does not find my files, even when they are readable.

I have the following directory /some set up

drwxr-xr-x  2 root root  4096 Sep 23 16:45 some

It's readable by everybody. Inside the directory I have one file called foundme.txt

-rw-r--r--  1 root student 157961 Sep 23 16:48 foundme.txt

Now, when I try to find this file as user student, I don't get any results other than permission errors. My understanding was that the directory and file were readable by student (and they are).

Can someone explain why this is failing?

$ find / -name "foundme.txt"
find: ‘/root’: Permission denied
  • find doesn't need to read the file foundme.txt, it just has to be able to list the contents of the directories; are you able to do find /some ? – Jeff Schaller Sep 23 '15 at 17:12
2

The find command starts at the top of the filesystem tree /, and searches for a file called foundme.txt. On its way to the /some folder it will include /root and a number of other directories that you do not have permission to access (for example, many of the pseudo-directories underneath /proc).

Accordingly, find warns you that it couldn't check those directories for the file.

If you leave find long enough it will discover your file as /some/foundme.txt. You can also discard the error/warning messages by appending 2>/dev/null to the end of the command (this instructs the shell to send everything written to stderr to the bit bucket rather than display it on the screen).

  • Thanks for helping out. I could hit myself right now. The file is found, but it's hidden in the warnings. For some reason, I was expecting that the file command would show the file at the end of the output. Thanks and sorry about that! – Jorre Sep 23 '15 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.