How do I remove "permission denied" printout statements from the find program?
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
.
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 otherfind
that supports the-readable
and-executable
predicates:
find / -type d ! \( -readable -executable \) -prune -o -type f -name netcdf -print
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).
Use locate(1)
instead:
$ locate netcdf
It will only show you files your user can see.