Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
2  
cp and mv are pretty good choices. What additional features do you need? For renaming, see unix.stackexchange.com/q/1136/8250 –  Lekensteyn May 6 '12 at 17:47
    
Yes there is. What files are you going to copy/move? –  Herman Torjussen May 6 '12 at 18:39
2  
What exactly do you mean by "batch copy" that you couldn't get done by cp or mv? –  Mat May 6 '12 at 18:39
    
@Lekensteyn and Mat: I'm trying to move every file in a directory I extracted from an archive into the directory aforementioned directory is contained in. –  rake May 6 '12 at 18:57
add comment

2 Answers 2

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.

share|improve this answer
add comment

You might get away nicely with rename as it's more apt to batch processing.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.