avoid permission denied spam when using find-command

21

3

I often try to find files with following syntax:

find . -name "filetofind"

However it usually results as many rows or error reporting (Permission denied) about folders where permission is denied. Is there any other way to avoid this spam than using sudo or advanced grepping from error-output?

user40167

Posted 2010-08-24T10:54:21.357

Reputation: 617

Related: http://stackoverflow.com/a/25234419/54964

– Léo Léopold Hertz 준영 – 2016-07-04T15:46:58.400

Answers

27

Try

find . -name "filetofind" 2>/dev/null

This will redirect stderr output stream, which is used to report all errors, including "Access denied" one, to null device.

whitequark

Posted 2010-08-24T10:54:21.357

Reputation: 14 146

Thanks, works like a charm :) I suppose there is no easy way to make it default option without creating an alias doing the same. – user40167 – 2010-08-24T11:01:53.700

No, this is by design of the shell. – whitequark – 2010-08-24T11:10:57.253

9

You can also use the -perm and -prune predicates to avoid descending into unreadable directories (see also How do I remove "permission denied" printout statements from the find program? - Unix & Linux Stack Exchange):

find . -type d ! -perm -g+r,u+r,o+r -prune -o -name "filetofind" -print

sdaau

Posted 2010-08-24T10:54:21.357

Reputation: 3 758

3

If you want to see other errors and you don't have files named "permission denied" then this will work "better".

find . -name "filetofind" 2>&1 | grep -v 'permission denied' 

Redirecting the output to grep with the inversion option.

Hogan

Posted 2010-08-24T10:54:21.357

Reputation: 1 284