对于某些明显的用法,grep命令可以输出多个关于搜索名称是目录的抱怨。请注意多个“是目录”警告,这通常发生在以下命令中: grep text *
例如:
/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
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用“-s”选项禁止有关目录的这些警告(和stderr可以重定向到NUL,但更糟糕),但我不喜欢这样,因为它是我们必须记住额外的样板每一次,它还会抑制所有警告,而不仅仅是关于目录的警告。
有什么办法可以在全球范围内永远压制这种虚假警告吗?我对 Debian 和 Cygwin 最感兴趣。
ton*_*ioc 12
根据您要处理目录内容的方式,
grep -d recurse
会这样做(处理递归目录),或grep -d skip
(忽略目录及其内容)。 您可以将其添加到 ~/.profile 或 ~/.bashrc(一个用户)或 /etc/profile 或 /etc/bashrc(所有用户)中,使其自动进行
alias grep="/bin/grep -d skip"
Run Code Online (Sandbox Code Playgroud)