首页 > 其他 > 详细

xargs -i参数详解

时间:2019-05-01 22:36:54      阅读:181      评论:0      收藏:0      [点我收藏+]

学习所需,文章装载过来!

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@jstuz6zw4s2vwp tmp]#ls

技术分享图片

[root@jstuz6zw4s2vwp tmp]# find . -type f -name "*.log" | xargs -i cp {} /tmp/k/

技术分享图片

[root@jstuz6zw4s2vwp tmp]# find . -type f -name "*.log" | xargs -I {} cp {} /tmp/n/

技术分享图片
结果出来了,
  加-i 参数直接用 {}就能代替管道之前的标准输出的内容;
  加 -I 参数 需要事先指定替换字符。

xargs -i参数详解

原文:https://www.cnblogs.com/xiaofeng666/p/10800939.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!