Wednesday, November 28, 2012

Argument list too long error

At times, you might get into a situation where you can't copy, move, remove or even list a huge number of files in a directory. When you attempt it, an error will be thrown saying "Argument list too long". This actually indicates that the OS has exceeded its Argument list limit. To know the Argument list limitation of your OS, run the following command "getconf ARG_MAX". It will show you the maximum number of arguments that can be passed to mv, cp, rm or ls command.

getconf ARG_MAX
   131072

To get rid of this problem, you must split your mv or cp command using wildcards.

Like instead of using "cp /folder1/* /folder2/ ",  we should use "cp /folder1/a* /folder2/; cp /folder1/b* /folder2/"
(or)
you can use 'for' loop construct as follows:

# for i in {a..z}; do cp /folder1/$i* /folder2/ ; done &
Please note in 'for' loop, for every cp command it executes, it creates a new process id.

3 comments:

  1. Hi, the whole thing is going nicely here and ofcourse every one is sharing information, that's actually excellent, keep up writing.

    My weblog :: magnum cash advance complaints

    ReplyDelete
  2. Replies
    1. Hi, Can you give an alternative syntax using 'xargs' ?

      Delete