xargs -i 参数或者-I参数配合{}即可进行文件的操作。
-I replace-s
tr
Replace occurre nces of replace-str in the initial-arguments with names read from standard input. A lso, 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 depre cated; use -I instead.
Replace occurre nces of replace-str in the initial-arguments with names read from standard input. A lso, 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 depre cated; 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
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]#
[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
[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 参数直接用 {}就能代替管道之前的标准输出的内容;