Ubuntu grep, find etc: "Permission denied" and "No such file or directory" output

with grep you could specifiy the -s flag which does pretty much what @ortang said

-s, --no-messages Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep's -q option. USG-style grep also lacked -q but its -s option behaved like GNU grep. Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead.

with find as far as I know @ortangs answer is the best. something like

find / -name "myfile" -type f -print 2>/dev/null


Try redirecting stderr to /dev/null.

johndoe@johndoe-desktop:/$ grep -rnP 'YII_CORE_PATH' ./ 2> /dev/null | grep -v .svn

Redirecting the strerr to /dev/null (a.k.a black hole) is a good way of suppressing permission denied errors.

However, do note that this wound not only suppress permission denied messages but ALL error messages.

If you do wish to retain error messages other than permission denied then you can do something like this -

grep -rnP 'YII_CORE_PATH' ./ 2>&1 | grep -v 'permission denied' > error.log

If you don't wish to retain those then the following would be just fine -

grep -rnP 'YII_CORE_PATH' ./ 2> /dev/null | grep -v .svn