For certain obvious usages, the grep command can output multiple complaints about search names being directories. Note the multiple "Is a directory" warnings, this typically happens with commands like: grep text *


/etc/webmin # grep "log=1" * 
grep: cluster-webmin: Is a directory
grep: cpan: Is a directory
grep: man: Is a directory
grep: mon: Is a directory

I know I can use the "-s" option to suppress these warnings about directories (and stderr can be redirected to nul, but that's even worse), but I don't like that because it's extra boilerplate which we have to remember every time, and it also suppresses all warnings, not just ones about directories.

Is there some way, where this spurious warning can be suppressed forever and globally ? I'm most interested in Debian and Cygwin.


Depending on the way you want to handle directories contents,

  • grep -d recurse will do it (handling recursively directories), or
  • grep -d skip (ignoring directories and their content).

You could have this be automatic, by adding it to ~/.profile or ~/.bashrc (one user) or /etc/profile or /etc/bashrc (all users)

alias grep="/bin/grep -d skip" 
|improve this answer|||||
  • This works nicely. I also found something called GREP_OPTIONS where the "-d skip" could be added instead. However, some bright spark somewhere decided that GREP_OPTIONS has been deprecated, and prints an annoying message when used, alas. So adding this as an alias (to profile or bashrc or whereever) is the best option. alias grep='/bin/grep -d skip' – William Mar 21 '18 at 19:22
  • @William - they'll remove GREP_OPTIONS due to problems it causes when writing portable scripts - hence the warning... – don_crissti Mar 21 '18 at 21:13

You could set an alias in your .profile or .bashrc:

alias grep='grep -s'

For global you could do it in /etc/profile or /etc/bashrc

|improve this answer|||||
  • I realize I can do this, and it would help with many cases of suppressing this warning. But, I am hoping for something which does not alter how grep is invoked/executed, and which won't suppress other grep warnings, and would work even for when grep isn't run (directly) by the shell. – William Mar 20 '18 at 13:40
  • As long as it's in your bashrc it will work from within scripts. – jesse_b Mar 20 '18 at 13:45

Just for completeness, GNU grep honours an environment variable called GREP_OPTIONS. From man grep:

      This variable specifies default options to be placed in front of
      any explicit options.  As  this  causes  problems  when  writing
      portable  scripts,  this  feature  will  be  removed in a future
      release of grep, and grep warns if it is used.   Please  use  an
      alias or script instead.

You can do export GREP_OPTIONS=-s, but, as the manpage says, this will also get passed on to scripts and might unintentionally mess up things.

For example, I have had GREP_OPTIONS=--color=always mess up configure scripts used for building software. Debugging that was a pain, it wasn't at all clear where the problem was.

|improve this answer|||||
  • See the comments to tonioc's answer, for why your solution is undesirable. – user1404316 Mar 22 '18 at 6:04
  • @user1404316 please read the answer itself to see why this is undesirable. – Olorin Mar 22 '18 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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