[OT] Argument list too long

Eldridge, Michael michael.eldridge at evolveddigital.com
Fri Aug 12 16:38:17 UTC 2005


> I try to copy my mp3's (108GB) from a nethd to the local
> hd on my box.  Nautilus just stops copy after some times
> (no message, just stops). So I tried it on the command
> line with cp and got:
> 
> thomas at AMD64:~$ cp -r /media/nethd/Sound/* /media/Sound/
> bash: /bin/cp: Argument list too long

this is an age-old issue.  unix systems typically have a
fixed size in which to place the environment and arguments.
newer linux distributions have this limit set at 128MiB.

xargs is one of the tools in any unix admin's swiss army
knife for this very reason.  xargs has a -n option that
will limit the number of arguments used per exec() of the
specified command line.  unfortunately, xargs isn't a
viable option in this case, because you need to specify
the source before the destination.  instead, use find:

	$ find /media/netHd/Sound/ -type f -exec cp -r {} /media/Sound \;

after looking at the manpage for cp, it seems you might
actually be able to get away with using it with the
--target-directory argument:

	$ ls /media/nethd/Sound | xargs -n 50 cp -r --target-directory=/media/Sound

this will copy 50 files at a time and should work out
for you.

-mike




More information about the ubuntu-users mailing list