40

What is the maximum length of command line arguments in gnome-terminal?

... and is there a system environment variable which reports this value?

Peter.O
  • 24,681
  • 2
    http://stackoverflow.com/questions/6846263/maximum-length-of-command-line-argument-that-can-be-passed-to-sqlplus-from-lin || http://askubuntu.com/questions/14081/what-is-the-maximum-length-of-command-line-arguments-in-gnome-terminal || http://serverfault.com/questions/163371/linux-command-line-character-limit || http://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument – Ciro Santilli OurBigBook.com Jun 22 '15 at 09:45

3 Answers3

34

xargs knows. On my system,

$ xargs --show-limits
Your environment variables take up 2572 bytes
POSIX upper limit on argument length (this system): 2092532
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2089960
Size of command buffer we are actually using: 131072
Chipaca
  • 9,990
  • 5
    To expand on this, the limit is not in the terminal, it's in the kernel (and in the shell, as well, but I think the default shell (bash)'s limit is as high as the kernel limit). Also, xargs isn't just for reporting the limit, it's also (primarily) for working around it — see the man page or other documentation. – Gilles 'SO- stop being evil' Nov 19 '10 at 22:57
  • 1
    I like this answer, particularly because of the "could actually use" output... I've twiddled with it a bit and came up with this command variant to isolate the "actually" value... (maybe there's a simpler way, but hey, it works and is suitable for a script: xargs --show-limits --no-run-if-empty < /dev/null 2>&1 |sed -n "/could actually use/s/.*: \\([0-9]\+\\)/\1/p" – Peter.O Nov 20 '10 at 04:57
  • 1
    Strangely, xargs seems to double-count the environment limit in the POSIX limit (POSIX limit = ARG_MAX - 2048 (headroom) - envvars). – Tobu Nov 17 '12 at 14:00
18

The answer comes from the sysconf value ARG_MAX. To examine it on your system:

getconf ARG_MAX

For me, this reports 2097152. For more details check the manpage:

man sysconf

To get this inside a program, for example:

#include <unistd.h>
...
printf("%ld\n", sysconf(_SC_ARG_MAX));
Kees Cook
  • 17,473
  • 1
    Thanks KC.. +1; a neat way to get the absolute MAX, but I've preferred the xargs method because of its "actually available" factor... as I was actually after a run-time value (but I didn't mention that :( – Peter.O Nov 20 '10 at 05:09
0

I don't really know about gnome-terminal, but the shell has not a 'fixed' limit, but the limit of the stack.

However there is an hardcode limit per-argument that is 128KB, that should not be a problem if you don't use 'very very very long arguments....'.

You can read more about this here:

http://www.mail-archive.com/bug-make@gnu.org/msg05522.html

OpenNingia
  • 3,303