Operating System - HP-UX
1758620 Members
1965 Online
108874 Solutions
New Discussion юеВ

Re: /bin/ls: Arg list too long

 
SOLVED
Go to solution
Marcel Heijblom
Occasional Advisor

/bin/ls: Arg list too long

When issuing an ls command I got above error.

This will probably have passed on this list.
Sorry for the inconvenience of the overhead,
but I need to know what to do about it ???

First think then act !!!
9 REPLIES 9
Sandor Horvath_2
Valued Contributor

Re: /bin/ls: Arg list too long

Hi !

You get this error from shell.
I think You have many many files in this directory and You give pattern for ls.

use find

find . -name "pattern"
or
find . -name "pattern -exec ls {} \;

regards, Saa
If no problem, don't fixed it.
Alex Glennie
Honored Contributor

Re: /bin/ls: Arg list too long

Sounds as if you are experiencing a limit with the operating system
that cannot be changed. .... How many files were you expecting back from the ls listing .... a large number I suspect ?

The shell generates this message when "exec()"
failes because the argument list exceeds available memory for arguments
and environment variables. The file /usr/include/sys/param.h defines
the variable NCARGS, which in turn defines the size for the argument
list. There is no way to change this value.... although the comments in
this file seem to indicate it is changeable, remember that all of the
Operating System has already been compiled based on the header file in
its current state. There are several Service Requests which have been
generated asking that the limit for NCARGS be increased, but until then,
you have two options:

1. Break your "ls" into smaller pieces - for example:

ls a*.gz
ls b*.gz
etc.

2. Try an alternate command. One example:

ls | grep .gz
Sandor Horvath_2
Valued Contributor

Re: /bin/ls: Arg list too long

Hi again !

I forget >

Try
getconf ARG_MAX
It show You the maximal size of argument.

regards Saa
If no problem, don't fixed it.
Victor BERRIDGE
Honored Contributor

Re: /bin/ls: Arg list too long

Hi,
There is a limit that I dont know by heart on arg values, that means you are certainly trying to list thousands of files..., you can use xargs as a workaround:
e.g.
ls ?xargs >outfile (Not worth trying to usr ? more since we are talking of large amount)

Do a man of xargs

Good luck
Victor
Frederic Soriano
Honored Contributor
Solution

Re: /bin/ls: Arg list too long

Hi Marcel,

If you are running HP-UX 10.20, there is a patch (PHKL_16751) that will add a new kernel parameter called "large_ncargs_enabled" which, if set to 1, will allow a much larger number of characters on the command line arguments (usually about 20K on 10.20).

Also, ARG_MAX found in /usr/include/limits.h indicates what this
limit is currently set at. Incidentally, this limit is much higher on 11.0 versus 10.20 (the patch on 10.20 will increase to the larger number that 11.0 allows - something like 200K).

I hope this helps.

Best regards.

Fred.
Bill Hassell
Honored Contributor

Re: /bin/ls: Arg list too long

It sounds like you have a massively large directory...not a good thing if it can be avoided. As you've seen, even a simple ls command will have problems. Performance in this directory will be a problem, other programs may have problems.

It's a good idea to arrange files in separate directories. Also, ARG_MAX still has an upper limit, with the patch on 10.20 up from 20,400 bytes on a single line to more than 2 million characters per line. But this may still be too small. It's a good idea to become familiar with xargs to remove all limitations for processing a command line list.


Bill Hassell, sysadmin
John McWilliams
Advisor

Re: /bin/ls: Arg list too long

I have had this problem so I split the ls into
sections ie if alpha characters do :-

ls a*

you will see all files starting with "a"
Les Schuettpelz
Frequent Advisor

Re: /bin/ls: Arg list too long

One other comment: depending on the numer of files in the directory and the length of the pathname used to list it, the ls command can cause this error with fewer files than you might think. Depending on context, it is best to do the 'ls' with the shortest possible relative path, ideally from . in the directory in question as current working directory, rather than, say, full-path from root. Any time the full path or a long relative path makes the arg list, it makes it once per file, which can add up fast.
Gary Stewart_1
Occasional Advisor

Re: /bin/ls: Arg list too long

Actually it turned out to be a corrupted /etc/MANPATH file. Thanks for all the input tho