What is the most efficient way to move a large number of files that reside in a single directory?
Taking advantage of GNU mv
's -t
option to specify the target directory, instead of relying on the last argument:
find . -name "*" -maxdepth 1 -exec mv -t /home/foo2/bulk2 {} +
If you were on a system without the option, you could use an intermediate shell to get the arguments in the right order (find … -exec … +
doesn't support putting extra arguments after the list of files).
find . -name "*" -maxdepth 1 -exec sh -c 'mv "$@" "$0"' /home/foo2/bulk2 {} +
Consider mv
ing the parent directory instead of the files:
mv /home/foo/bulk /home/foo2/bulk2 && mkdir /home/foo/bulk
(But it might cause problems if /home/foo/bulk
must exist at every moment.)