27

我正在寻找一个本地 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
4

1 回答 1

28

默认情况下,grep 不会忽略不存在或不可读的文件。您需要提供-sor--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.)
于 2013-04-30T10:40:37.760 回答