I've got a setup where I need to use 'find' to find 0 or more files in a certain directory, however, 'find' always produces an error when there are no files that match a certain check. Is it possible to run 'find' while having it omit errors when no files match the pattern?

link|improve this question

69% accept rate
2  
GNU find does not report such errors by default, at least not on my systems. – grawity Aug 21 '11 at 10:36
feedback

2 Answers

up vote 1 down vote accepted

Like @grawity said find isn't expected to report these errors. Anyway if you want to suppress error output redirect stderr to /dev/null:

find  . HERE_YOUR_FIND_PARAMS 2&> /dev/null

One typical case in which find write to stderr happens when there is a directory in your find searching sub-path that hasn't the permission to be opened.

link|improve this answer
Thanks, this works as I needed it to. – Eli Aug 21 '11 at 19:39
feedback

Can you just ignore the errors? Or, more specifically, redirect them to /dev/null?

link|improve this answer
I'm using the results in a script, so no, I can't just ignore the errors. Redirecting stderr to /dev/null works, however. – Eli Aug 21 '11 at 19:39
feedback

Your Answer

 
or
required, but never shown

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