日期:2014-05-16  浏览次数:20716 次

小白求教一个关于xargs参数的问题,有实例
find . -size -124c|xargs -i rm {}
这条命令很简单:找出小于124字节的文件,删除之。
但是有二点不明:
1,参数 i 的作用是什么
2,{}的作用是什么,发现有的必须有{},否则报错,有的则不需要,请详解

------解决方案--------------------
这2个要连在一起看:
http://blog.csdn.net/andy572633/article/details/7214534

$ ls 
------解决方案--------------------
 xargs -t -i mv {} {}.bak
-i 选项告诉 xargs 用每项的名称替换 {}。-t 选项指示 xargs 先打印命令,然后再执行。

------解决方案--------------------
http://bbs.chinaunix.net/thread-4083205-1-1.html

xargs与find经常结合来进行文件操作,平时删日志的时候只是习惯的去删除,比如
find . -type f -name "*.log" 
------解决方案--------------------
 xargs rm -rf *
就将以log结尾的文件删除了,如果我想去移动或者复制就需要使用参数来代替了。
 
xargs  -i 参数或者-I参数配合{}即可进行文件的操作。
 
-I replace-str
              Replace  occurrences  of  replace-str  in the initial-arguments with names read from standard input.  Also, unquoted blanks do not terminate
              input items; instead the separator is the newline character.  Implies -x and -L 1.

       --replace[=replace-str], -i[replace-str]
              This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise.  This option is deprecated; use -I  instead.
man了一下看的还是不太懂,通过例子,做作实验将我的理解写一下。
 
############### 操作的目录下的文件###############
[root@test05 ab]# ls
1kk.zip  3kk.zip  5kk.zip  b.rar  d.rar  f.rar  h.rar  j.rar  mini.txt  ni.txt
2kk.zip  4kk.zip  a.rar    c.rar  e.rar  g.rar  i.rar  k.rar  nii.txt