> I would like to find all the mp3 files in a drive, move them to another
> drive and put them in the correctly-named directories.
>
> Example:
>
> pseudocode:
> Find mp3
> Move mp3 <dirname> #Dirname same as directory file was found in.
> end
>
> So that all the Aerosmith mp3 found go into an Aerosmith directory and
> so on.
Not sure if this can be done with move (mv).
But I can come up with a copy (cp) that copies only the mp3’s and creates
the correct dirs at destination:
cd source/
find ./ -type f -iname “*.mp3” -exec cp -v --parents ‘{}’ destination/ ‘;’
If all files have been copied, without errors, you can clean up:
find ./ -type f -iname “*.mp3” -exec rm -v ‘{}’ ‘;’
I’m sure there’s a more elegant way, but don’t have the time (sorry).
Just to be pedantic. This is all about files whose names end with the characters .mp3. That is not the same as MP3 files, those are files whose contents are according the MP3 definition.
I suppose it does not matter in your case, but it helps understanding things when you realize this
just want to mention that amarok is also able to sort your music files physical on the disk. It is also highly customizable so that you surely get your preferred directory names and file names.
> Just to be pedantic.
Don’t. It irritates people, distracts the thread from the OP’s question and
usually serves little purpose.
> This is all about files whose names end with the
> characters .mp3. That is not the same as MP3 files, those are files
> whose contents are according the MP3 definition.
Very true. But then most people would have added the comment that not all
their MP3 files have the usual extension. That would change the search a
bit, of course.
To me, the OP’s question was not really about MP3’s anyway, but rather about
reproducing the original directory structure, while making a selective copy
of files. It seems likely to me he knew how to make a full recursive move
(but that would’ve taken ALL files), and how to use find to make a simple
move (but then the directory would not be reproduced). I have learned about
the --parents option of cp recently, and figured it would help him.
> I suppose it does not matter in your case, but it helps understanding
> things when you realize this
Maybe it does. What things?
There may be newbies here who don’t realize that Linux is case-sensitive when processing data. You comment may prevent confusion on their part. Thank you for the help.