find . -name "*.[chCH]" -print | etags -

来源:互联网 发布:windows不能安装在usb 编辑:程序博客网 时间:2024/05/21 10:53

find的-print

       -print True; print the full file name on the standard output,  followed

              by  a  newline.    If  you  are  piping  the output of find into
              another program and there is the faintest possibility  that  the
              files  which you are searching for might contain a newline, then
              you should seriously consider using the -print0  option  instead
              of  -print.   See  the UNUSUAL FILENAMES section for information
              about how unusual characters in filenames are handled.


       -print0
              True; print the full file name on the standard output,  followed
              by  a  null  character  (instead  of  the newline character that
              -print uses).  This allows file names that contain  newlines  or
              other  types  of white space to be correctly interpreted by pro‐
              grams that process the find output.  This option corresponds  to

              the -0 option of xargs.


etags 后面的 - 表示etags把前面find的结果从stand input中读入,因为etags不是管道命令,所以只能用这种方法。当然还可以使用xargs达到同样的效果。


find . -name "*.[chCH]" | xargs etags 也可以达到同样的效果,但是因为xargs默认按空白符隔断,所以find出来的文件名中不能有空白符。

find . -name "*.[chCH]" -print0 | xargs -0 etags 可以处理文件名中有空白符的情况。

xargs的原理:

假如find的结果有两个分别是./test.c    ./main.c,那么xargs会以空白符位间隔,识别出这两个文件名放到etags后面作为参数,等同于etags ./test.c ./main.c

- 的原理见鸟哥6.7节。

原创粉丝点击