xargs
跳转到导航
跳转到搜索
后接命令时,将标准输入作为参数传递给命令;否则将解析出来的输入输出到标准输出。
参数
-a
- 指定从文件而不是 stdin 读取。这时 xargs 并不会把子进程的 stdin 重定向到
/dev/null
-d
- 指定分隔符
-Istr
- 指定替换用的字符串。会隐含
-L 1
-L N
- 每条命令消耗最多
N
条非空行 -i
- 指定替换用的字符串,默认为 {}。不建议使用
-P N
- 同时执行
N
条命令[1]
BSD 特定的参数
-o
- 将子进程的 stdin 重定向到
/dev/tty
而不是/dev/null
-J replstr
- 使用一个指定的占位字符串来指定参数放置的位置(而不是默认的命令结尾)。只有第一个
replstr
会被替换。[2][3]
技巧
调用编辑器
xargs sh -c 'vim "$@" < /dev/tty' vim
其中,最后的 vim 是程序名( argv[0]
),命令参数由 xargs 设置。这相当于 BSD 版本的 -o
参数
参见
外部链接
- xargs(1): build/execute from stdin - Linux man page
- Man Page for xargs (freebsd Section 1)
- OpenBSD Manual Pages: xargs(1)
参考资料
- ↑ UNIX Command Line: Unix xargs parallel execution of commands
- ↑ [1]
-I
和-J
的比较 - ↑ findutils - Patches: patch #4916, [PATCH] xargs -J (FreeBSD... [Savannah], 给 GNU findutils 的一个关于支持
-J
的补丁