几个常用的xargs使用例子

来源:互联网 发布:web数据挖掘 pdf 编辑:程序博客网 时间:2024/05/16 00:50

xargs是一个非常有用的命令。下面给出我常用的几个例子:


假设有文件 f 内容如下:

abc123456789qwertyop

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