tech_log: Suppressing annoying find / -name "something" error messages like "find: `/proc/1/fd': Permission denied"

Tuesday, December 16, 2008

Suppressing annoying find / -name "something" error messages like "find: `/proc/1/fd': Permission denied"

Have you ever tried looking for some file like this:

drasko@kanta:~$ find / -name "some_file.c"
find: `/.mozilla': Permission denied
find: `/proc/tty/driver': Permission denied
find: `/proc/1/task/1/fd': Permission denied
find: `/proc/1/task/1/fdinfo': Permission denied
find: `/proc/1/fd': Permission denied
find: `/proc/1/fdinfo': Permission denied
find: `/proc/2/task/2/fd': Permission denied
find: `/proc/2/task/2/fdinfo': Permission denied
find: `/proc/2/fd': Permission denied
find: `/proc/2/fdinfo': Permission denied
find: `/proc/3/task/3/fd': Permission denied
find: `/proc/3/task/3/fdinfo': Permission denied
find: `/proc/3/fd': Permission denied

and many lines like this...

Eventually, you loose yourself in this and do not see the eventual hit. You do not see the tree because of the forest.

Now, you will not get out easily just by piping this to grep, like:
drasko@kanta:~$ find / -name "some_file.c" | grep some_file.c
because these "Permission denied" lines do not go to the stdout but to stderr, so they will be displayed anyway.

Solution is to redirect stderr out of find to /dev/null:

drasko@kanta:~$ find / -name "some_file.c" 2> /dev/null
/home/drasko/some_file.c
drasko@kanta:~$


Here you go.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home