Argument list too long

Posted by Planet Malaysia on December 2, 2008

advertisement

Have you seen error message: “Argument list too long” on Linux or Unix console before?

Basically this is a shell command line length limitations. The error “Argument list too long error message” occurs which anytime a user feeds too many arguments to a single command. Each command under Linux/UNIX accepts a parameter commonly known as command arguments. Normally it apply to Linux or Unix system commands such as ls *, cp *, rm *, mv * and etc.

Find out current command line length limitations:
# getconf ARG_MAX

Result:
131072

To get a better result, you may type command
# echo $(( $(getconf ARG_MAX) – $(env | wc -c) ))

Result:
129006

Man HELP:
getconf – print system configuration variables
wc – print the number of newlines, words, and bytes in files
-c, –bytes print the byte counts

For an example, I have more than 15000 files name filesync.blah.blah in my /tmp folder. Whenever I type ls /tmp/filesync*, I will get an error message “Argument list too long” as attached image below:

Argurment Too Long

How to overcome the error message? Use find or xargs command.
The solution are:
# echo /that/directory/*|xargs ls

# find /that/directory|xargs ls

This is NOT work in my case.
# find /tmp/file* -exec ls {} \;

Possibly Related Posts:


Comments

One Response to “Argument list too long”

  1. Manuel Ricardo on December 10th, 2008 2:05 am

    maybe u can also work with a for … but it is more complex:

    for files in * ; do ls $files ; done

    you can replace * to a path for example:

    for files in /misc ; do ls $files ; done

Leave a Reply




Planet Malaysia

  • Follow us on Twitter


  • web www.planetmy.com