I'm trying to enter a command with VERY big argument (1 MB in size), but it says "Argument list too long." How can I enter that argument?

OS: Linux Ubuntu

  • 2
    Depends on the OS. – ilkkachu Apr 27 '17 at 17:11
  • @ilkkachu Linux Ubuntu – MCCCS Apr 27 '17 at 17:11
  • 3
    Oh, right, a single big argument. Linux has a fixed limit for that, so you can't go over it without recompiling the kernel. See: What defines the maximum size for a command single argument? – ilkkachu Apr 27 '17 at 17:14
  • 4
    What command are you attempting to use? – Timothy Martin Apr 27 '17 at 17:21
  • 1
    1MB isn't very big, though it's bigger than ARG_MAX on my macOS Sierra (262144). On Ubuntu 16.04, it seems to be larger: docker run --rm ubuntu:latest getconf ARG_MAX produces 2097152 for me, so you should be able to pass 1MB of argument string on Ubuntu. – tripleee Apr 28 '17 at 3:40

There is no way to pass an argument between executables if it is larger than the kernel's ARG_MAX limit.

If you have a list of arguments which is too long, splitting it up into smaller pieces can be done e.g. with xargs. This runs the command as many times as necessary, supplying as many arguments as will fit.

The syntax is xargs command <file. If you omit command, it displays its arguments, like echo.

As a demo,

xargs -n 4 </etc/motd

will print the first four tokens on one line (first invocation), the next four through another, etc. (The -n argument sets a maximum number of arguments, so this doesn't use the ARG_MAX limit at all.)

If the command you want to run has side effects which are undesirable, this might not work. For example, if the command will overwrite any previously existing ./a.out file, you will obviously be left with the results from just the last run after it finishes.

If you can configure or modify command so it reads a file, or standard input, instead of a command-line argument, that will work around the restriction. A file or stream can be much larger than ARG_MAX, and often is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.