Commando to find and move mp3 file and directory

Hello, I have a lot of mp3 in a various directory. My goal is a command that find all mp3 file and move the files and directory where is the mp3 file to a destination folder.
Is it possible?

Thanks in advance

The below snippet will search for mp3s in /home/ and all sub-directories inside /home/ and move it to /home/user/mp3s/

for x in `find /home/ -name "*.mp3"`; do mv $x /home/user/mp3s/; done

Hello, thanks for replay, but does the script move the directory where is the mp3 file to a new destination?

Thanks

It'll move anything that has '.mp3' in its name.

find ~ -name *.mp3 -exec mv {} /home/user/mp3Dir \;

Should move all the melodies to the mp3Dir directory . :slight_smile:

:smiley:

find -name *.end |
awk 'BEGIN 
{ FS="/"; pwd=ENVIRON["PWD"]; pa=pwd; }
{z=0;for(i=2;i<=NF:i++){ z++; if(i<NF){printf "mkdir " $i "\n"; printf "cd " $i "\n"; pa=pa "/" $i }else{ printf "mv " pa "/" $i " " $i "\n"}} 
for(i=1;i<z;i++){printf "cd ..\n"} pa=pwd}'

for testing mode operations are just printed out...

Some errors noted upon casual inspection:

find is missing the path argument. The pattern argument to the -name primary must be protected from shell expansion.

Also, there's a colon where a semicolon should be in the for loop's expression list.

Not an error; just an observation:
mkdir -p can create all intermediate pathname components with a single invocation.

Regards,
Alister

1 Like

thanx for checking my code - I retyped and didn't copy this line.
I've executed this syntax (find) in bash shell and got no error messages.
maybe I don't fully understand what you try to say?

oh nice, this makes it more simple.. :slight_smile: