Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
find: `/root/.dbus': Permission denied
find: `/root/.gconf': Permission denied
find: `/root/.gconfd': Permission denied
find: `/root/.gnome': Permission denied
find: `/root/.gnome2': Permission denied
find: `/root/.gnome2_private': Permission denied

E.g. output like this when I run the "find / -name netcdf" command

share|improve this question

3 Answers 3

up vote 10 down vote accepted

Those messages are sent to stderr, and pretty much only those messages are generally seen on that output stream. You can close it or redirect it on the command-line.

$ find / -name netcdf 2>&-

or

$ find / -name netcdf 2>/dev/null

Also, if you are going to search the root directory (/), then it is often good to nice the process so find doesn't consume all the resources.

$ nice find / -name netcdf 2>&-

This decreases the priority of the process allowing other processes more time on the CPU. Of course if nothing else is using the CPU, it doesn't do anything. :) To be technical, the NI value (seen from ps -l) increase the PRI value. Lower PRI values have a higher priority. Compare ps -l with nice ps -l.

share|improve this answer

Use locate(1) instead:

$ locate netcdf

It will only show you files your user can see.

share|improve this answer
1  
This assumes that updatedb is running regularly. That is not the case on all Linux systems. –  Arcege Aug 26 '11 at 0:48
2  
If locate(1) is installed, its database should be updated periodically. If that isn't happening, I'd class that a misconfiguration rather than a fault of locate(1). Additionally, it only takes a few minutes to run it by hand in the rare cases where you're looking for a file that was added since the last DB update. I find myself doing that maybe half a dozen times per year, an overhead easily paid for from the speed advantage of locate(1) over find(1). –  Warren Young Aug 26 '11 at 3:03

I would just like point out this answer by @Gilles in Exclude paths that make find complain about permissions - Unix & Linux Stack Exchange; it basically involves a construct for find that makes it not descend unreadable directories, and in that sense, is probably also a bit faster.

This would seem to work for me:

With GNU find or any other find that supports the -readable and -executable predicates:

find / -type d ! -readable ! -executable -prune -o -type f -name netcdf -print

(Edit: just tried this exact command, and I got "find: '/var/lib/php5': Permission denied", where it has permissions drwx-wx-wt, and owned by root; but the following command didn't report a single permission denied: )

or also this:

find / -type d ! -perm -g+r,u+r,o+r -prune -o -type f -name 'netcdf' -print

For some reason, I need to add all of the g+r,u+r,o+r (shortcut for that is a+r), otherwise if one of them is left out, I may still get "Permission Denied" hits.

Here is a breakdown of how I see this (note the -a (and) operator in find is implicit between two predicates):

find /         # find starting from path /
  -type d        # match type is directory
  ! -perm -a+r   # (and) match not permissions of `r`ead present 
  -prune         # ignore what matched above and do not descend into it
  -o             # or (whatever didn't match above)
  -type f        # match type is file
  -name 'netcdf' # (and) match name is 'netcdf'
  -print         # print what matched above

Note that without the last -print, I get some extra items shown (that have nothing to do with -name 'netcdf'); the -print ensures that only the name matches are printed (if any).

share|improve this answer
1  
If find(1) can't descend into a directory, it won't. So checking beforehand if it can or not will just add work (check twice), and thus slow it down. –  vonbrand Mar 23 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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