Below a manual method. If you want a script you will need to provide a sample of the directories and the files. Problem with scripts... if it is coded wrongly the script does not care... it will execute what you think wrongly possibly creating an unrecoverable end result.
If possible make a backup first. rm
and mv
can mess things up when used wrongly. To test what you want to do you can use ls
and cp
with the same 2nd part and see if what would be done is done correctly.
You can remove files from subfolders using a wildcard.
rm */*.flac
will remove files ending in .flac
from the current location, 1 directory deep. You can add more /*
to it to go deeper into the directory structure (rm */*/*.flac
for 2 directories deep etc). The same applies for moving files:
mv */*.mp3 .
will move all files 1 directory deep and ending in .mp3 to the current directory. mv */*/*.mp3 .
does 2 directories deep.
If you have lots of subdirectories (and not just 1 or 2 levels deep) this will move all mp3's found inside the current directory, regardless how deep and put them in the current directory:
find . -iname "*.mp3" -exec mv {} . \;
This will remove all the files ending in .flac
from the current directory, regardless how deep:
find . -type f -name '*.flac' -exec rm {} \;
What I normally do is create a new folder OUTSIDE of the current directory and copy all the mp3 files over to that directory and when you confirm it is done correctly remove the directory that holds all the flac and directories. It is less error prone.
So if I am in /home/rinzwind/musicfiles/ I would create /home/rinzwind/mp3/ and do something like this 1st.
find /home/rinzwind/musicfiles/ -iname "*.mp3" -exec mv {} /home/rinzwind/mp3/ \;