Why does recursive grep show 'No such file or directory' errors?

大城市里の小女人 提交于 2019-12-04 15:26:38

问题


I'm grepping a local svn directory. When I run grep -r "pattern" . I get some errors such as

grep: ./Data/test: No such file or directory

Who asked grep to look for non-existent files?


>grep --version
grep (GNU grep) 2.10

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

回答1:


By default, grep would not ignore non-existent or unreadable files. You need to supply the -s or --no-messages option in order to do so. Quoting from 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.)


来源:https://stackoverflow.com/questions/12851128/why-does-recursive-grep-show-no-such-file-or-directory-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!