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
###################使用 i 参数 ##################
[root@test05 ab]# find . -type f -name "*.txt" | xargs -i
cp {}  /tmp/k/
[root@test05 ab]# ls ../k/
mini.txt  nii.txt  ni.txt
[root@test05 ab]#
###################  使用 I  参数 ################
[root@test05 ab]# find . -type f -name "*.txt" | xargs -I {} cp {}  /tmp/n/
[root@test05 ab]# ls ../n/
mini.txt  nii.txt  ni.txt
 
结果出来了,
  加-i 参数直接用 {}就能代替管道之前的标准输出的内容;

加 -I 参数 需要事先指定替换字符

转自

xargs的i参数 - CSDN博客 https://blog.csdn.net/luojiafei/article/details/7213489

最新文章

  1. 显示python已安装模块及路径,添加修改模块搜索路径
  2. 怎样处理“error C2220: warning treated as error - no object file generated”错误
  3. 删除Xcode中的 证书文件
  4. zend studio 配置 apache服务器事宜
  5. 爬虫3 html解析器 html_parser.py
  6. iOS开源JSON解析库MJExtension
  7. WPF如何实现拖拽打开文件(将文件拖进窗体打开)
  8. WCF配置文件详解 【转】
  9. 45种Javascript技巧大全(转)
  10. Oracle 安装安全补丁过程中出现的问题
  11. DATABASE LINK 的查看、创建与删除
  12. nopcommerce 二次开发
  13. Web桌面应用框架2:著名的WEB桌面应用分析
  14. 关于python使用threadpool中的函数单个参数和多个参数用法举例
  15. Linux(二十二)Ubuntu安装和配置
  16. iOS XIB使用中适配iPhoneX的安全区域、调用UiView动画
  17. 像黑客一样使用Linux命令行(转载)
  18. ORA-00600: internal error code, arguments: [13030], [20]一例解决
  19. (转)LVS+Keepalived使用总结 vip丢失
  20. [Web 前端] MobX

热门文章

  1. 【Luogu5108】仰望半月的夜空(后缀数组)
  2. 手动实现property装饰器
  3. Android在初始化时弹出popwindow的方法
  4. Android学习系列(17)--App列表之圆角ListView(续)
  5. 【codevs4829】数字三角形++
  6. Codeforces Round #514 (Div. 2) D. Nature Reserve
  7. excel自动化翻译2
  8. ISO七层模型详解
  9. 搭建nginx反向代理用做内网域名转发
  10. js 定义像java一样的map方便取值【转】