How can I exclude all “permission denied” result lines from “grep”?

The messages you are receiving is due to a lack of permission on those files, i.e., those are error messages.

All you have to do is to redirect the stderr (standard error output) to /dev/null, like this:

grep -irl "foo" 2> /dev/null

To lear more about redirection (on bash), read this article:
Bash Reference Manual – Redirections

Edit: You can also just suppress error messages by using:

grep -irl "foo" 2>&-

Leave a Comment