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.
$ getconf ARG_MAXSample outputs:
2097152
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 flavours. I recommend that you go through this web page for detailed information.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 5 comments… read them below or add one }
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!
Hi,
Please explain why you are using env| wc …
thanks
echo $(( $(getconf ARG_MAX) – $(env | wc -c) ))
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.
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.
how do i find java for my tablet