What is the maximum character length of arguments in a shell command? How do I find out the maximum length of arguments for a new process under Linux or Unix like operating systems?

If you get an error that read as – command: Argument list too long due to limit for the command line length.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time N/A
UNIX / Linux / BSD system has a limit on how many bytes can be used for the command line argument and environment variables. You need to use the getconf command to query system configuration variable called ARG_MAX.
ARG_MAX, maximum length of arguments for a new process

Fig.01: ARG_MAX, maximum length of arguments for a new process

Get maximum length of arguments for a new process

The following command will provide the upper limit for your system under Linux operating systems:
$ getconf ARG_MAX
Sample outputs:

2097152

So I can pass the 2097152 bytes worth args to any shell command. The following bash code will provide you exact number:

echo $(( $(getconf ARG_MAX) - $(env | wc -c) ))

POSIX suggests to subtract 2048 additionally so that the process may savely modify its environment:

expr `getconf ARG_MAX` - `env|wc -c` - `env|wc -l` \* 4 - 2048

Sample outputs:

2092496

Please note that the maximum length of arguments for a new process may differ among unix flavors. I recommend that you go through this web page for detailed information.


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • Filipe Oct 3, 2012 @ 12:57

    I understand that you subtract 2048 to allow process to modify env variables, I just don’t get it why you subtract byte count from env command, and line count? Could you explain it please? Thanks!

  • Jalal Hajigholamali Oct 4, 2012 @ 12:03

    Hi,

    Please explain why you are using env| wc …

    thanks

    echo $(( $(getconf ARG_MAX) – $(env | wc -c) ))

    • 🐧 nixCraft Oct 6, 2012 @ 8:35

      You need to get the effectively usable space. You need to consider the space consumption by both argv[] (arguments) and envp[] (environment). So you’ve to decrease ARG_MAX at least by the results of “env|wc -c” and “env|wc -l * 4”. POSIX suggests to subtract 2048 additionally so that the process may savely modify its environment. See linked article at the bottom of faq for more info.

  • Stef Oct 5, 2012 @ 17:24

    My guess is that `env | wc -c` gives the size needed to store all environment variables (names and values). Envirnoment variables are not global. Each process has a fulk copy inherited from its parent process.

    `env | wc -l ` * 4 gives the number of environment variables multiplied by 4. This is probably the size needed to allocate a table of pointers (or offsets or sizes) to speedup the accesses to the environment variables.

  • mary ann smith Oct 11, 2012 @ 16:26

    how do i find java for my tablet

  • Dan Feb 2, 2017 @ 8:32

    2097152 Jelly beans is the max? Why don’t you add the units of measurement. Are we talking about bytes? Character length?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum