linux command xargs: maximum size of the arguments passed by it?

user685275 picture user685275 · Apr 24, 2011 · Viewed 7.7k times · Source

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

Answer

Mat picture Mat · Apr 24, 2011

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.

From the xargs man page, for reference:

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.