您的位置:首页 > 其它

几个常用的xargs使用例子

2012-09-28 18:23 316 查看
xargs是一个非常有用的命令。下面给出我常用的几个例子:

假设有文件 f 内容如下:

abc

123
456
789
qwe
rty
op


test命令把命令行输入原样输出,源码如下:

#include <stdio.h>

int main(int argc, char **argv)
{
for(int i=0; i<argc; ++i)
printf("%s ", argv[i]);
printf("\n");
return 0;
}


cat f|xargs ./test
输出:
./test abc 123 456 789 qwe rty op

cat f|xargs -n 1 ./test
输出:
./test abc
./test 123
./test 456
./test 789
./test qwe
./test rty
./test op

cat f|xargs -n 1 ./test xxx
输出:
./test xxx abc
./test xxx 123
./test xxx 456
./test xxx 789
./test xxx qwe
./test xxx rty
./test xxx op

cat f|xargs -I aaa -n 1 ./test aaa xxx
输出:
./test abc xxx
./test 123 xxx
./test 456 xxx
./test 789 xxx
./test qwe xxx
./test rty xxx
./test op xxx

cat f|xargs -i -n 1 ./test {} xxx
输出:
./test abc xxx
./test 123 xxx
./test 456 xxx
./test 789 xxx
./test qwe xxx
./test rty xxx
./test op xxx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: