Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im using the following to serch for a string in all the files in a directory.

grep -Flr --include "*" 'mystring' /modules/

Which works perectly fine and returns the files which contain the string. However I also get a list of files with permission denied next to them which means looking for the results a bit harder.

Is there a flag to pass to the command to ignore outputting permission denied errors.


share|improve this question

migrated from Jan 8 '10 at 13:59

This question came from our site for professional and enthusiast programmers.

I usually just use:

grep -Flr --include "*" 'mystring' /modules/ 2>/dev/null

which will throw away all output to standard error, assuming you have a shell allowing for 2> standard error redirection. If not, see here.

If (as you seem to indicate in your comment), your version of grep outputs its errors to standard output rather than standard error, you can filter that output with something like:

grep -Flr --include "*" 'mystring' /modules/ | egrep -v 'Permission denied|ERROR'

This will throw away lines based on whatever pattern you deem is necessary.

share|improve this answer
Thanks however for me it didn't work. I found the following to work: grep -Flr --include "*" 'mystring' /modules/ | grep -v Perm – shambl3 Sep 18 '09 at 11:09
The default shell on FreeBSD is tcsh, which doesn't recognize 2>. – Roland Smith Dec 28 '14 at 15:13

If you are using BSD grep, use the -s flag;

grep -Flrs --include "*" 'mystring' /modules/

Additionally, I think you can drop the --include "*" because BSD grep reads directories by default and recurses over them if you use -r or -R.

share|improve this answer

You must log in to answer this question.