Wednesday, July 15, 2009

The parameter list is too long...

It is somewhat common to get an error message like the one in the title. When there are lots of file in a directory, either removing or doing any kind of operation with them is a little bit annoying. There is an article called "Avoid common errors in UNIX and Linux" published on July 14th at IBM developerWorks AIX and UNIX section. I want to include the related part , which summarizes the issue well and gives a solution for it, here:*

./foo: /usr/bin/ls: 0403-027 The parameter list is too long.

A program has been running for months on your IBM® AIX® computer without issue. But while the program is running, it creates a file every few minutes in the same directory for logging. The file names begin with f. and e.. The directory is becoming full, and the ls command is slowing down drastically on response time. That is understandable, because the directory has so many files in it.

A few more months go by, and the AIX program continues to run consistently and without problem. There are now 100,000 files that begin with f. and another 100,000 files that begin with e. Now, when you attempt to clean up the log directory of only the files that begin with f., you receive the following message:

# rm ~cormany/logs/f.*
ksh: /usr/bin/rm: 0403-027 The parameter list is too long.

I guess you waited too long before cleaning up the files. No time like the present, however.

When executing a command like delete, all arguments are validated and expanded before execution. The example provided is looking for ~cormany/logs/f.*, which expands to become 100,000 arguments to the command rm. In other words, instead of rm ~cormany/logs/f.*, what is actually being executed is rm ~cormany/logs/f.1 ~cormany/logs/f.2 ~cormany/logs/f.3 … ~cormany/logs/f.100000.

AIX, like other UNIX and Linux operating systems, has a set size for the number of command-line arguments and environment variables that can be used. To view the set size in AIX, use the command getconf. Per the man page for getconf, you should look at ARG_MAX:

# man getconf

ARG_MAX
Maximum length, in bytes, of the arguments for one of the exec
subroutines, including environment data.

# getconf ARG_MAX
1048576


This value tells you that you have 1,048,576 bytes you can use for environment variables and command-line arguments to execute. It looks like you exceeded that. To resolve this issue, two options are available:

  • Increase the amount via smitty chgsys and change ARG/ENV list size in 4K byte blocks or via chdev. I do not recommend changing a system-wide parameter every time you run into this type of error out of convenience: This should be the last resort.
  • Rather than using the command rm with 100,000 arguments, which will fail miserably, the command find does a much better job of removing the files:
    # find ~cormany/logs –name “f.*” –exec rm {} \;

    The find command searches the directory for any files beginning with f. rather than placing the burden on the shell's command line. The find command then executes rm on each file found, thus removing every file beginning with f.


By the way, xargs can be another alternative (may be the first) for resolving this issue, as well. Today, I experience a problem with a script which gives the error; \script[5]: no space. Using xargs also resolves this issue (actually the main problem is the too many file names in the find command, find .... | xargs ls can also solve the problem but, changing the first line to #!/bin/bsh also solves the problem)

* The whole article can be accessed from http://www.ibm.com/developerworks/aix/library/au-unixerrors/index.html

1 comment:

  1. If you wanna save some brain power just do it this way.

    From windows command line
    ftp -i [insert server name]
    login
    cd /cormany/logs
    mdelete f.*

    Many ways to skin a cat and all that.

    ReplyDelete