为什么递归grep显示'没有这样的文件或目录'错误?

时间:2012-10-12 01:48:10

标签: grep symlink

我正在使用本地svn目录。当我运行grep -r "pattern" .时,我遇到了一些错误,例如

  

grep:./ Data / test:没有这样的文件或目录

谁让grep查找不存在的文件?


>grep --version
grep (GNU grep) 2.10

>lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04 LTS

1 个答案:

答案 0 :(得分:23)

默认情况下,grep不会忽略不存在或不可读的文件。您需要提供-s--no-messages选项才能执行此操作。引自man grep

   -s, --no-messages
          Suppress  error  messages about nonexistent or unreadable files.
          Portability note: unlike GNU grep, 7th Edition Unix grep did not
          conform to POSIX, because it lacked -q and its -s option behaved
          like GNU grep's -q option.  USG-style grep also  lacked  -q  but
          its  -s  option  behaved  like GNU grep.  Portable shell scripts
          should avoid both -q and -s and  should  redirect  standard  and
          error output to /dev/null instead.  (-s is specified by POSIX.)