Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482141
  • 博文数量: 108
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 1134
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-29 19:43
文章分类

全部博文(108)

文章存档

2016年(10)

2015年(9)

2014年(73)

2013年(16)

我的朋友

分类: LINUX

2014-06-10 22:56:16

       -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.
 -print 打印文件全名到标准输出后面接\n.如果用管道输出到另外一个程序,那么需要考虑用-print0而不是-print

       -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 programs that process the find  output.   This option corresponds to the -0 option of xargs。
-print0 打印全名到标准输出,后面接一个空字符。这个允许文件名含有\n或者是空格。



       -prune True; if the file is a directory, do not descend into it. If -depth is given, false; no effect.  Because -delete implies -depth,  you  cannot  usefully use -prune and -delete together.
如果是目录那么返回真并且不进入该目录,如果指定了-depth选项那么返回false。没有效果,因为 -delete会暗示用到-depth,不能同时使用-prune 和-delete选项。



   UNUSUAL FILENAMES
       Many of the actions of find result in the printing of data which is under the control of other users.  This includes file names, sizes, modification times  and so forth.  File names are a potential problem since they can contain any character except '\0' and '/'.  Unusual characters in file names can do unexpected and often undesirable things to your terminal (for example, changing the settings of your function keys on some terminals).  Unusual characters are handled differently by various actions, as described below.
许多find的查找结果会在其他用户的控制之下,包括文件名,大小,修改时间等等。文件名是一个潜在的问题,因为他可以包含任何字符(除了\0和/以外).文件名中含有不常用的字符经常是不所希望看到的而且经常会带来一些意外的问题,比如:改变一些终端上的热键,这些不常用的字符可以用以下的行为来处理。
-print0, -fprint0
              Always print the exact filename, unchanged, even if the output is going to a terminal.
-print0,-fprint0 总是准确的打印文件名,即使输出到终端。

       -ls, -fls
    Unusual characters are always escaped.  White space, backslash, and double quote characters are printed using C-style escaping (for  example  '\f',  '\"').   Other unusual characters are printed using an octal escape.  Other printable characters (for -ls and -fls these are the characters between octal 041 and 0176) are printed as-is.
  -ls.-fls 不常用的字符总是被“摆脱“,空格,\ ""会以C的格式打印出来,其他的会以8进制格式打印。

       -printf, -fprintf
              If the output is not going to a terminal, it is printed as-is.  Otherwise, the result depends on which directive is in use.  The directives %D, %F,  %g, %G, %H, %Y, and %y expand to values which are not under control of files' owners, and so are printed as-is.  The directives %a, %b, %c, %d, %i,%k, %m, %M, %n, %s, %t, %u and %U have values which are under the control of files' owners but which cannot be used to send arbitrary data  to  the terminal,  and  so these are printed as-is.  The directives %f, %h, %l, %p and %P are quoted.  This quoting is performed in the same way as for GNU ls.  This is not the same quoting mechanism as the one used for -ls and -fls.  If you are able to decide what format to use for the output of  find then it is normally better to use '\0' as a terminator than to use newline, as file names can contain white space and newline characters.  The setting of the 'LC_CTYPE' environment variable is used to determine which characters need to be quoted


       -print, -fprint
              Quoting is handled in the same way as for -printf and -fprintf.  If you are using find in a script or in a situation where the matched files  might  have arbitrary names, you should consider using -print0 instead of -print.



       cd /source-dir
       find . -name .snapshot -prune -o \( \! -name *~ -print0 \)|
       cpio -pmd0 /dest-dir


       This command copies the contents of /source-dir to /dest-dir, but omits files and directories named .snapshot (and anything in them).  It also omits files or  directories  whose  name  ends  in  ~,  but not their contents.  The construct -prune -o \( ... -print0 \) is quite common.  The idea here is that the  expression before -prune matches things which are to be pruned.  However, the -prune action itself returns true, so the  following  -o  ensures  that  the
       right  hand  side  is  evaluated only for those directories which didn't get pruned (the contents of the pruned directories are not even visited, so their
       contents are irrelevant).  The expression on the right hand side of the -o is in parentheses only for clarity.  It  emphasises  that  the  -print0  action
       takes  place  only for things that didn't have -prune applied to them.  Because the default 'and' condition between tests binds more tightly than -o, this
       is the default anyway, but the parentheses help to show what is going on.

       find repo/ -exec test -d {}/.svn -o -d {}/.git -o -d {}/CVS ; \
       -print -prune


       Given the following directory of projects and their associated SCM administrative directories, perform an efficient search for the projects' roots:


       repo/project1/CVS
       repo/gnu/project2/.svn
       repo/gnu/project3/.svn
       repo/gnu/project3/src/.svn
       repo/project4/.git


       In this example, -prune prevents unnecessary descent into directories that have already been discovered (for example we do not search project3/src because
       we already found project3/.svn), but ensures sibling directories (project2 and project3) are found.





阅读(2153) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~