Answer the question
In order to leave comments, you need to log in
How to copy several thousand files from one directory to another?
Simple task: copy files from /tmp/src to /tmp/dst. /tmp/src contains several thousand files.
On FreeBSD, the usual solution doesn't work:
cp -p /tmp/src/* /tmp/dst
Error: "/sbin/cp: Argument list too long." So I decided like this:
find /tmp/src -type f -exec cp -p {} /tmp/dst \;
Is it possible to do something differently or easier? How about in other *nixes?
Answer the question
In order to leave comments, you need to log in
Don't use *, which the shell will expand into an argument list. Copy the entire directory.
cp -raT /tmp/src /tmp/dst The
key parameter is -T. Make it work properly even if the dst directory already exists
If you already use find, then it's better like this:
find /tmp/src -type f -exec cp -p -t /tmp/dst {} \+
works much faster than your version. If find is better with xargs.
In general, it worked great in FreeBSD:
cp -a src/ tmp/
Notice the slashes at the end. Works with both the existing dst/ folder and the missing one.
man xargs
I don't remember the exact parameters, but something like this:
ls -1|xargs -n 30 cp -d destignation
The key is the maximum number of arguments per entry (-n) and -d for cp (allows you to swap dest and src).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question