首页 技术 正文
技术 2022年11月15日
0 收藏 880 点赞 4,865 浏览 1189 个字

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参数 – luojiafei的专栏 – CSDN博客
http://blog.csdn.net/luojiafei/article/details/7213489

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,498
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,911
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,745
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,501
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,139
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,303