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

人气:339 发布:2022-10-16 标签: linux limit command size xargs

问题描述

似乎xargs不会一次传递所有参数,在手册中说xargs 执行命令(默认为/bin/echo)一次或多次,我听说这样做的原因是 xargs 将传入的参数分成组并将它们逐组传递给命令.如果这是正确的,有人知道这个组的大小是如何确定的吗?谢谢

It seems that xargs doesn't pass all the arguments at once, in says in the manual that xargs executes the command (default is /bin/echo) one or more times, I heard that the reason for this is that xargs chops the passed in arguments into groups and pass them to the command group by group. If this is correct, anyone knows how this group size is determined? Thanks

推荐答案

使用 --show-limits 参数.它将列出您系统上的现有限制.

Use the --show-limits argument. It will list the existing limits on your system.

$ 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

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

The group size depends on the length of each argument passed in and the limits listed above.

来自 xargs 手册页,供参考:

From the xargs man page, for reference:

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

The POSIX standard allows implementations to have a limit on the size of arguments to the exec functions. This limit could be as low as 4096 bytes including the size of the environment. For scripts to be portable, they must not rely on a larger value. However, I know of no implementation whose actual limit is that small. The --show-limits option can be used to discover the actual limits in force on the current system.

516