cp/mv/etc : argument list too long ... I am sick of this

Bill Campbell freebsd at celestial.com
Mon Dec 5 15:10:11 PST 2005


On Mon, Dec 05, 2005, user wrote:
>
>Ok, so I have some big directories with lots of files.  If I do mv or cp,
>it always refuses, telling me:
>
>cp: argument list too long
>
>so, no problem ... I get creative with things like this:
>
>for f in 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W
>X Y Z ; do cp $f* /some/dir ; done
>
>lame, but it works.

man xargs

Copying individual files isn't an ideal application for xargs
since it breaks its standard input into arguments, but it works
great for many things.  Find all files containing some pattern
one might use:

	find . -type f print | xargs grep -l pattern

If files may contain funny characters (e.g. whitespace)

	find . -type f -print0 | xargs -0 grep -l pattern

The example above copying files is probably best handled with
cpio or tar:

	find . -print | cpio -pdumv destdir

Disclaimer:  I'm accustomed to the gnu-ish behaviour of these
tools, and FreeBSD routines may differ.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

``If we got one-tenth of what was promised to us in these acceptance
speeches there wouldn't be any inducement to go to heaven.''
    Will Rogers


More information about the freebsd-questions mailing list