I have thousands of mp3s inside a complex folder structure which resides within a single folder. I would like to move all the mp3s into a single directory with no subfolders. I can think of a variety of ways of doing this using the find command but one problem will be duplicate file names. I don’t want to replace files since I often have multiple versions of a same song. Auto-rename would be best. I don’t really care how the files are renamed.
Does anyone know a simple and safe way of doing this?
You could change a
a/b/c.mp3path intoa - b - c.mp3after copying. Here’s a solution in Bash:find srcdir -name '*.mp3' -printf '%P\n' | while read i; do j="${i//\// - }" cp -v "srcdir/$i" "dstdir/$j" doneAnd in a shell without
${//}substitution:find srcdir -name '*.mp3' -printf '%P\n' | sed -e 'p;s:/: - :g' | while read i; do read j cp -v "srcdir/$i" "dstdir/$j" doneFor a different scheme, GNU’s
cpandmvcan make numbered backups instead of overwriting — see-b/--backup[=CONTROL]in the man pages.find srcdir -name '*.mp3' -exec cp -v --backup=numbered {} dstdir/ \;