12

似乎 xargs 并没有一次传递所有参数,在手册中说 xargs executes the command (default is /bin/echo) one or more times,我听说这样做的原因是 xargs 将传入的参数分组并逐组传递给命令。如果这是正确的,有人知道这个组的大小是如何确定的吗?谢谢

4

1 回答 1

22

使用--show-limits论据。它将列出您系统上的现有限制。

$ xargs --show-limits
Your environment variables take up 4108 bytes
POSIX upper limit on argument length (this system): 2090996
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2086888
Size of command buffer we are actually using: 131072

组大小取决于传入的每个参数的长度和上面列出的限制。

xargs手册页,供参考:

POSIX 标准允许实现对 exec 函数的参数大小进行限制。此限制可能低至 4096 字节,包括环境的大小。对于可移植的脚本,它们不能依赖更大的值。但是,我知道没有实现的实际限制如此之小。--show-limits 选项可用于发现当前系统上的实际限制。

于 2011-04-24T17:51:30.427 回答