I wanted to search for the text " Starting kernel" in a directory, so I did this:

 [root@xilinx petalinux-v2013.10-final]# grep -r "Starting kernel"  
grep: warning: tools/packagemanager/lib/i686: recursive directory loop

grep: Xilinx-ZC702-14.7/build/linux/rootfs/targetroot/etc/init.d/functions: No such file or directory
grep: Xilinx-ZC702-14.7/build/linux/rootfs/targetroot/etc/rcS.d/S10flashdev: No such file or directory
grep: Xilinx-ZC702-14.7/build/linux/rootfs/targetroot/mnt/net: No such file or directory
grep: Xilinx-ZC702-14.7/build/linux/rootfs/targetroot/mnt/cf: No such file or directory
Binary file Xilinx-ZC702-14.7/pre-built/linux/images/u-boot.elf matches
Binary file Xilinx-ZC702-14.7/pre-built/linux/images/BOOT.BIN matches
Binary file Xilinx-ZC702-14.7/pre-built/linux/images/output.bin matches

Why is it searching in files that don't exist? Why am I getting these "No such file or directory" messages?

Also, why is it searching binary files when I gave it ASCII characters? Can a binary file contain a string like mine?

4 Answers 4


That is most likely because those are links that point to no existing files.

You should look at one of the files e.g.:

ls -l Xilinx-ZC702-14.7/build/linux/rootfs/targetroot/etc/init.d/functions

and then again do ls on where it points to.

You can also do:

ls -L Xilinx-ZC702-14.7/build/linux/rootfs/targetroot/etc/init.d/functions

which will probably get you cannot access: .... as well.


grep, by default, doesn't ignore non-existent or unreadable files. You need to supply the -s or --no-messages option in order to make grep ignore those. 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.)

Because you use -r option, so grep will search recursively, include symlinks.

-R, -r, --recursive
              Read all files under each directory, recursively;
              this is equivalent to the -d recurse option.

Like @Anthon's answer, maybe some symlinks under parent directory is not existed or broken.

By default, grep also search string in binary file:

              If the first few bytes of a file indicate that the file
              contains binary data, assume that  the  file  is  of  type  TYPE. 
              By default, TYPE is binary, and grep normally outputs either a 
              one-line message saying that a binary file matches, or no message 
              if there is no match. If TYPE is without-match, grep assumes that a 
              binary file does not match; this is equivalent to the -I option. 
              If TYPE is text, grep processes a binary file as if it were text;
              this is equivalent to the -a option. Warning: grep --binary-files=text
              might output binary garbage, which can have nasty side effects 
              if the output is  a  terminal  and  if  the terminal driver
              interprets some of it as commands.

A binary file can also contain some strings. You can do a simple check by using strings command on a binary file:

strings /usr/bin/basename

man grep contains :

-I     Process a binary file as if it did not  contain  matching  data;
       this is equivalent to the --binary-files=without-match option.
  • This partially answers half of the question; you really need to explain things when you post answers. Mar 17, 2014 at 20:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .