简体   繁体   中英

questions on Linux command “find -exec {}”

I tried to update a file in subversion. I need to add a line in makefile, in order to build up the revised version of code. Here is the command I tried to find the place in make file.

find . -name "*ake*" -exec grep filename {} /dev/null \\;

It works. But my questions are: 1. What is the "\\;" for? If I change it, there will be error message.

2 The /dev/null didn't change the results. I know this is the device where dispose all the "garbage information". But I still don't quite understand it in this situation.

Thanks in advance!

The \\; indicates the end of the command to be executed by find . The \\ is required to stop the shell interpreting the ; itself. From man find :

-exec command ;
          Execute  command;  true  if  0 status is returned.  All following 
          arguments to find are taken to be arguments to the command until an 
          argument consisting of ‘;’ is encountered.

The /dev/null is a clever trick that took me a while to figure out. If grep is passed more than one filename it prints the containing filename before each match. /dev/null acts as an empty file containing no matches, but makes grep think it is always passed more then one filename. A much clearer alternative suggested by richard would be to use grep's -H option:

       -H, --with-filename
              Print the filename for each match. This is the default when there 
              is more than one file to search.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM