Chinaunix首页 | 论坛 | 博客
  • 博客访问: 512064
  • 博文数量: 138
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 716
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-03 21:48
文章分类

全部博文(138)

文章存档

2019年(1)

2017年(5)

2016年(99)

2015年(33)

我的朋友

分类: LINUX

2016-08-17 16:28:42


点击(此处)折叠或打开

  1. [root@SVNServer test]# man xargs
  2. XARGS(1) XARGS(1)

  3. NAME
  4.        xargs - build and execute command lines from standard input

  5. SYNOPSIS
  6.        xargs [-0prtx] [-E eof-str] [-e[eof-str]] [--eof[=eof-str]] [--null] [-d delimiter]
  7.        [--delimiter delimiter] [-I replace-str] [-i[replace-str]] [--replace[=replace-str]]
  8.        [-l[max-lines]] [-L max-lines] [--max-lines[=max-lines]] [-n max-args] [--max-args=max-args]
  9.        [-s max-chars] [--max-chars=max-chars] [-P max-procs] [--max-procs=max-procs]
  10.        [--interactive] [--verbose] [--exit] [--no-run-if-empty] [--arg-file=file] [--show-limits]
  11.        [--version] [--help] [command [initial-arguments]]

  12. DESCRIPTION
  13.        This manual page documents the GNU version of xargs. xargs reads items from the standard
  14.        input, delimited by blanks (which can be protected with double or single quotes or a back-
  15.        slash) or newlines, and executes the command (default is /bin/echo) one or more times with
  16.        any initial-arguments followed by items read from standard input. Blank lines on the stan-
  17.        dard input are ignored.

  18.        Because Unix filenames can contain blanks and newlines, this default behaviour is often
  19.        problematic; filenames containing blanks and/or newlines are incorrectly processed by xargs.
  20.        In these situations it is better to use the -0 option, which prevents such problems. When
  21.        using this option you will need to ensure that the program which produces the input for
  22.        xargs also uses a null character as a separator. If that program is GNU find for example,
  23.        the -print0 option does this for you.

  24.        If any invocation of the command exits with a status of 255, xargs will stop immediately
  25.        without reading any further input. An error message is issued on stderr when this happens.

也就是说
linux文件名有的可能包含空格的 比如创建一个文件 touch a\ b.txt  ,这样的话,会生成一个带空格的文件名,
在使用的时候用args处理时候,xargs会默认使用空格作为分隔,认为是a文件和 b.txt这两个文件,所以会造成误操作的情况,官方给出的处理方法是在 处理的时候 加上-0 ,将'\0'作为分隔符,这样做的前提是需要保证xargs的输入源中在最后的时候才能含有null字符,中间不能含有。因此在跟find命令结合使用的时候,需要在find命令的后面添加  -print0 参数而不是-print.
此为操作隐患,需要注意

另外看下一find的参数描述

点击(此处)折叠或打开

  1.         -print True; print the full file name on the standard output, followed by a newline. If
  2.               you are piping the output of find into another program and there is the faintest pos-
  3.               sibility that the files which you are searching for might contain a newline, then you
  4.               should seriously consider using the -print0 option instead of -print. See the
  5.               UNUSUAL FILENAMES section for information about how unusual characters in filenames
  6.               are handled.

  7.        -print0
  8.               True; print the full file name on the standard output, followed by a null character
  9.               (instead of the newline character that -print uses). This allows file names that
  10.               contain newlines or other types of white space to be correctly interpreted by pro-
  11.               grams that process the find output. This option corresponds to the -0 option of
  12.               xargs.
    因此在处理的时候要额外的注意!
阅读(709) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~