Each of the other
find commands posted so far has a problem! OK, its actually the
mv command that has a problem...
Many Linux users are used to the
-i option to
mv always being there because of an alias many distributions (notably RedHat) put in the
.bashrc file ... but when used in find as has been shown here, the -i option will not be aliased in... as a result, duplicated filenames will be lost, with only the last "found" file remaining.
The
mv -i option prevents "clobbering" like-named files by interactively prompting you to confirm any overwrite. Being an "old-timer," I get annoyed by the -i (especially on
cp)and comment out
all of the aliases in my .bashrc -- but that's because I'm an old-timer!
Maybe this would be no loss for music files (because you're not likely to keep them all named music.mp3 or anything), but if there are other files (backup.tgz or something) then you'll clobber them! (I know that both my Eric Claption "Layla.mp3" files are really very different! -- One is the original, the other is "unplugged" & I'd hate to lose either one!)
I'm not so sure about the benefit (at least in this instance) of xargs over -exec -- but in either case above, the -i option added to the mv command might very well prevent the loss of some valuable music!
For any newbies, this results in the command:
Code:
find ~ -xdev -iname '*mp3' -exec mv -i '{}' /home/you/some/dir \;
NOTE: I also added a place for find to look (other than CWD): the ~ is your home directory. And I placed quotes around the {} in mv just in case there are spaces or other wierdnesses in my file/directory names.
Peace, Love, and Unix!