问题
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