Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

grep

symlink

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 
like image 726
user13107 Avatar asked Oct 12 '12 01:10

user13107


People also ask

How do I recursively grep a directory?

Grep command is used to search text from files. It is a versatile pattern that invokes grep with –r. –R option search files recursively from subdirectories, starting from the current directory.

How do you use recursive grep?

To recursively search for a pattern, invoke grep with the -r option (or --recursive ). When this option is used grep will search through all files in the specified directory, skipping the symlinks that are encountered recursively.

Which flag should be used for a recursive grep?

By default, grep will search all files in a given folder and its subfolders if you invoke it with the recursive -r flag.

What does the V flag do for grep?

Due to the -v flag, these lines will be removed from the output. In this context, the grep command will filter the output of git branch --merged . The latter outputs a list of branches, out of which the current branch is marked with an asterisk. grep -v "\*" simply removes the current branch from the output.


1 Answers

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.) 
like image 83
devnull Avatar answered Oct 20 '22 23:10

devnull