$ touch {a..f} $ mkdir dir1 dir2 $ ls | xargs a b c d dir1/ dir2/ e f $ ls > f # -a读取文件中的内容 $ xargs -a f a b c d dir1/ dir2/ e f # 将文件中的多行转换为一行显示 $ seq 1 5 > line $ more line 1 2 3 4 5 $ xargs -a line 1 2 3 4 5 # 增加一行单独的END作为结束符 $ more f a b c d END dir1/ dir2/ e f # 指定结束符,通常为单独的一行END,也可以指定为其他字符串,如下的单独一行e $ xargs -af -eEND a b c d $ xargs -af -ee a b c d END dir1/ dir2/
# 创建文件f,文件内容为3行,每行有4列 $ more f line1 arg1 arg2 arg3 line2 arg1 arg2 arg3 line3 arg1 arg2 arg3 $ xargs -af -l1 line1 arg1 arg2 arg3 line2 arg1 arg2 arg3 line3 arg1 arg2 arg3 $ xargs -af -n1 line1 arg1 arg2 arg3 line2 arg1 arg2 arg3 line3 arg1 arg2 arg3 # -l以换行符为分隔符,则一行显示原来的2行内容 $ xargs -af -l2 line1 arg1 arg2 arg3 line2 arg1 arg2 arg3 line3 arg1 arg2 arg3 # -n以空格为分隔符,则一行显示原来的2个参数 $ xargs -af -n2 line1 arg1 arg2 arg3 line2 arg1 arg2 arg3 line3 arg1 arg2 arg3 $ ls | xargs -l a b c d dir1/ dir2/ e f $ ls | xargs -l3 a b c d dir1/ dir2/ e f # -d指定分隔符 $ echo"a,b,c,d,e,f,1,2,3" > f $ xargs -a f -d , a b c d e f 1 2 3 $ xargs -af -d, -n3 a b c d e f 1 2 3 # -t每次先显示命令在执行,默认执行echo命令 $ ls | xargs -t -l3 echo a b c a b c echo d dir1/ dir2/ d dir1/ dir2/ echo e f e f