为什么递归grep显示'没有这样的文件或目录'错误? [英] Why does recursive grep show 'No such file or directory' errors?

查看:1371
本文介绍了为什么递归grep显示'没有这样的文件或目录'错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查找本地svn目录。当我运行 grep -rpattern。我遇到一些错误,比如


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


谁问过 grep $查找不存在的文件?

$ b $ $ p $ > grep - -version
grep(GNU grep)2.10

> lsb_release -a
没有LSB模块可用。
经销商编号:Ubuntu
描述:Ubuntu 12.04 LTS


解决方案

默认情况下,grep不会忽略不存在或不可读的文件。您需要提供 -s - no-messages 选项才能这样做。从引用man grep


   - s,--no-messages 
禁止关于不存在或不可读文件的错误消息。
可移植性注释:与GNU grep不同,第7版Unix grep没有
符合POSIX,因为它缺少-q,它的-s选项表现为
,就像GNU grep的-q选项一样。 USG风格的grep也缺少-q,但
的-s选项表现得像GNU grep。可移植shell脚本
应该避免-q和-s,并且应该将标准错误输出和
错误输出重定向到/ dev / null。 (-s由POSIX指定)



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

解决方案

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.)

这篇关于为什么递归grep显示'没有这样的文件或目录'错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆