Bash Script to move Files

Gordon Messmer yinyang at eburg.com
Sat Oct 8 06:02:45 UTC 2005


Thom Paine wrote:
> 
> The example I was starting with was:
> 
> find -name *.tmp -exec rm -rf {} \;
> 
> And I tried to get it to seek out all my *.ogg files and dump them into 
> a media folder.

like:

find . -name '*.ogg' -exec mv {} /media/oggs \;

> To prevent it from moving files repeatedly, I changed to the directory I 
> wanted to search and moved it to a different directory on another mount.

It won't move anything repeatedly, but it'll over write files with the 
same name.  It'll also move directories, if their name ends in ".ogg"

> I can't get it to work though. I thought I could substitute rm -rf with 
> mv /media/oggs but that didn't seem to work.

The name of the file that matches the contstraints you described to 
"find" is substituted for the {} after -exec.  Since mv expects the 
source before the destination, you'd need to use "mv {} /destination"




More information about the fedora-list mailing list