[OT] Argument list too long

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


> > Am Freitag, 12. August 2005 18:18 schrieb Thomas Kaiser (ubuntu):
> > > thomas at AMD64:~$ cp -r /media/nethd/Sound/* /media/Sound/
> > > bash: /bin/cp: Argument list too long
> > 
> > Untested(!):
> > $ find /media/nethd/Sound -type f --maxdepth 1 -print0 | 
> xargs -0 cp 
> > --target-directory=/media/Sound
> 
> this will not solve the problem, as xargs is used for building
> command lines.  all you've done is moved the overhead of creating
> the command line from the shell globbing to a separate binary.
> you solve nothing by using this and create additional overhead
> in the process.

i am mistaken.  max-lines defaults to 1.  from what i can remember,
this was not the case in the past.  this solution will work, but
you will not get any subdirectories or files in those subdirectories
due to the -type and -maxdepth arguments to find.

my original proposal for using xargs with -n is the best of any
of the solutions (except the solution for just copying the parent
directory, which is obviously the preferred choice) for the 
following reasons:

    -	find's -exec argument will fork() and exec() for each file,
	creating a crapload of additional overhead
    -	using xargs with the default max-lines of 1 will fork() and
	exec() for each line of input (only one file per line),
	creating a crapload of additional overhead

using the -L (max-lines) or -n (max-args) options of xargs is the
best way to go about it in order to reduce the number of processes
required to complete the task.

-mike




More information about the ubuntu-users mailing list