Unix / Linux: Maximum Character Length of Arguments In a Shell Command

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. 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.

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.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts