xargs里面n1参数有什么作用

回复 收藏
打扰一下,我想问下 xargs里面n1参数有什么作用?是对象一个一个处理吗

[root@linux1 ~]# mkdir test
[root@linux1 ~]# cd test
[root@linux1 test]# touch 1.txt 2.txt 3.txt 4.txt 5.txt
[root@linux1 test]# ls
1.txt  2.txt  3.txt  4.txt  5.txt
[root@linux1 test]# ls |xargs -n1 -i {} cp {} {}_bak
xargs: {}: 没有那个文件或目录
[root@linux1 test]# ls |xargs -n1 -i{} cp {} {}_bak
[root@linux1 test]# ls
1.txt      2.txt      3.txt      4.txt      5.txt
1.txt_bak  2.txt_bak  3.txt_bak  4.txt_bak  5.txt_bak
[root@linux1 test]# ls bak
ls: 无法访问bak: 没有那个文件或目录
[root@linux1 test]# ls  *bak
1.txt_bak  2.txt_bak  3.txt_bak  4.txt_bak  5.txt_bak
[root@linux1 test]# ls  *bak |xargs -i{} cp {} {}_bak2
[root@linux1 test]# ls
1.txt           2.txt           3.txt           4.txt           5.txt
1.txt_bak       2.txt_bak       3.txt_bak       4.txt_bak       5.txt_bak
1.txt_bak_bak2  2.txt_bak_bak2  3.txt_bak_bak2  4.txt_bak_bak2  5.txt_bak_bak2

我执行了这段脚本,感觉n1参数没什么作用~
2016-08-01 23:57 举报
已邀请:
0

maria

赞同来自:

本帖最后由 maria 于 2016-8-2 09:21 编辑

-n1是指每次只传递一个参数给xargs命令,比如
echo "1 2 3 4"|xargs -n1
1
2
3
4
echo "1 2 3 4"|xargs -n2
1 2
3 4
0

18038036038

赞同来自:

那在我这条命令中
ls |xargs -n1 -i{} cp {} {}_bak
ls  *bak |xargs -i{} cp {} {}_bak2
是等效的吧
0

maria

赞同来自:

18038036038 发表于 2016-8-2 09:52
那在我这条命令中
ls |xargs -n1 -i{} cp {} {}_bak
ls  *bak |xargs -i{} cp {} {}_bak2

是的
0

18038036038

赞同来自:


明白了~非常感谢!!

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: