Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 611
user685275 Avatar asked Apr 24 '11 17:04

user685275


People also ask

What does the xargs command do in Linux?

The xargs command builds and executes commands provided through the standard input. It takes the input and converts it into a command argument for another command. This feature is particularly useful in file management, where xargs is used in combination with rm , cp , mkdir , and other similar commands.

What does xargs return?

EXIT STATUS xargs exits with the following status: 0 if it succeeds 123 if any invocation of the command exited with status 1-125 124 if the command exited with status 255 125 if the command is killed by a signal 126 if the command cannot be run 127 if the command is not found 1 if some other error occurred.

What is xargs I option?

xargs gets the needed arguments from standard input (the standard input). Different options tell how the standard input is to be interpreted to obtain these arguments. -I placeholder Specifies that each line in the standard input (the standard input) is to be considered as a single argument.

What is xargs n1 Linux?

-n1 tells xargs to run the given command once per argument. So if you have something like echo file1 file2 file2 | xargs basename. That's equivalent to basename file1 file2 file2.


1 Answers

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.

like image 168
Mat Avatar answered Oct 12 '22 11:10

Mat