Is there a way to batch copy/move files in unix? I thought it might be an option for cp/mv
but I can't find any way to do it.

- 231
2 Answers
cp
and mv
are both good tools for copying files and moving files respectively. Combined with shell constructs (loops like for file in *; do ...; done
) or find
, they become even more powerful.
If I understood your purpose correctly, you have extracted files like:
somedir/file.png
somedir/file.txt
and want to move all files into the parent directory such that it looks like:
file.png
file.txt
Using shell wildcards, assuming that you are in the directory somedir
, you can use:
mv * ../
*
is a glob pattern that expands to all files in the current directory. If you have hidden files (files and directories with a leading .
in their filename), use shopt -s dotglob
in bash
).
I've mentioned find
before. If you have a tree of files like:
somedir/000.txt
somedir/a/001.txt
somedir/a/004.txt
somedir/b/003.txt
somedir/b/002.txt
somedir/whatever/somethingunique.txt
and want to move all files in one directory (say, seconddir
), use:
find -exec mv {} seconddir/ \;
This assumes that all filenames are unique, otherwise files would get overwritten.

- 20,830
cp
andmv
are pretty good choices. What additional features do you need? For renaming, see http://unix.stackexchange.com/q/1136/8250 – Lekensteyn May 06 '12 at 17:47cp
ormv
? – Mat May 06 '12 at 18:39