linux命令xargs:它传递的参数的最大大小?

问题描述:

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

使用--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选项可用于发现当前系统上的实际限制。

+0

这太好了,谢谢。 – user685275 2011-04-25 03:02:40

+1

具有讽刺意味的是,'--show-limits'选项[不是'xargs'的POSIX标准的一部分](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html),所以你可以不依靠它。 (我认为这是一个GNU扩展。) – 2017-05-02 23:02:08