cp 1500+ Files

Hello,

I need to copy 1500+ files (total of 170mb) from our /tmp/directory to a different directory /application/program/files

I issue the command:

user@host[tmp/directory]> cp * /application/program/files

I am getting the follwing error:

ksh: /usr/bin/cp: arg list too long

being new to aix, I have never seen this error. Can someone point me in the right direction.

do you check by copying one file ?

Yes, copying one file works.

Did you search this forum before posting your question? You would have found lots of answers to this common problem like this one.

try with

ulimit -f 100

ulimit -f returns unlimited

The reason has nothing to do with AIX and everything with how the shell works: if you enter a "file glob" (like the "*" you used) it is not presented to the program but evaluated by the shell prior to feed its results to the program.

That means: if you enter the command as above and your directory holds only two files, "a" and "b", what the "cp" command would get is:

cp a b /application/program/files

(in case you wonder: "cp" would get "a" and "b" marked as both being source files).

In your case the list into which the asterisk expands is very, very long. Now, the command line in the shell is limited in length (as far as i remember it is 4k per default). This is why you get the error message.

The solution is to either use the directory name instead of "*" or use another utility: "find" or "tar".

With "find":

cd /your/source/directory ; find . -type f -exec cp {} /path/to/destination \;

or, with "tar":

# cd /your/source/dir
# tar -cf - . | (cd /your/destination/dir ; tar -xf - )

I hope this helps.

bakunin

1 Like