linux 中xargs -i 和-I在使用上的区别

发布时间 2023-05-08 22:10:08作者: 小鲨鱼2018

 

001、 -i

[root@PC1 test]# ls
[root@PC1 test]# touch a.txt a.csv
[root@PC1 test]# ls
a.csv  a.txt
[root@PC1 test]# find ./ -name "*.txt" | xargs -i cp {} {}.bak     ## -i单独传递参数
[root@PC1 test]# ls
a.csv  a.txt  a.txt.bak

 

02、-I

[root@PC1 test]# ls
[root@PC1 test]# touch a.txt a.csv
[root@PC1 test]# ls
a.csv  a.txt
[root@PC1 test]# find ./ -name "*.txt" | xargs -I cp {} {}.bak   ## 报错
xargs: {}: No such file or directory
[root@PC1 test]# ls
a.csv  a.txt

 

-I的正确用法:

[root@PC1 test]# ls
[root@PC1 test]# touch a.txt a.csv
[root@PC1 test]# ls
a.csv  a.txt
[root@PC1 test]# find ./ -name "*.txt" | xargs -I {} cp {} {}.bak   ## 正确用法
[root@PC1 test]# ls
a.csv  a.txt  a.txt.bak