How long can the command line be?
This page attempts to explain the meaning and the consequences
of the ARG_MAX kernel constant. It's more or less related
Useless Use of X Award page
and a recurring topic in
The value of the constant ARG_MAX defines how long an
argument list your kernel can take on the command line before
it chokes. Here's a script to find out the value of it:
And here are some results from various machines I happen to have access to:
# Print out the system's architecture
uname -rms # or uname -a
# Let the C preprocessor read in the system's limits from limits.h
# and then expand the macro ARG_MAX
# Filter out excess output (there will be some line number information
# and a gadzillion empty lines)
# On some gcc systems, I have been unable to find a working cpp.
# You can use gcc -E - <:<:HERE | tail -1 in that case.
cpp <<HERE | tail -1 # Only the last line is interesting
POSIX requires ARG_MAX to be at least 4096 bytes.
There are allegedly old systems with ARG_MAX set as low as
2048 or even 1024 bytes.
On a system with a low value for ARG_MAX, you will often end up
with the shell saying Too many arguments or
Argument list too long when you attempt something like
Linux 2.0.33 i686
SunOS 5.4 sun4m
SunOS 4.1.3 sun4c
Curiously, SunOS 4 knows about _POSIX_ARG_MAX,
which is correctly set to 4096.
SunOS 4.1.1 allows a megabyte of information to be passed
OSF1 V4.0 alpha
IRIX 5.3 IP12
There is something funny about how IRIX does these things
but I found the value 5120 in an #ifndef in limits.h
NetBSD 1.2C mac68k
(256 * 1024)
(For the lazy people without
that's 262144 bytes.)
ls * */*
and of course
On any system, the last of the examples is going to blow up sooner or later.
This is why we have
for f in `find . -print`; do
This is of course still not a secure construction
(depending of course on what the : something attempts to do).
find . -print |
xargs : something
W. Richard Stevens, Advanced Programming in the Unix Environment,
p30f, p39; p209
Addison-Wesley, 1992; ISBN 0-201-56317-7
Back to Unix Award Page