Linux – suppress grep directory warnings globally

greplinux

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 *

eg:

/etc/webmin # grep "log=1" * 
grep: cluster-webmin: Is a directory
config:log=1
grep: cpan: Is a directory
grep: man: Is a directory
miniserv.conf:log=1
miniserv.conf:syslog=1
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.

Best Answer

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" 
Related Question