My music collection contains 'Artist Name' folders, many of which contain subfolders with an 'Album Name'. If there are no 'Album Name' folders in the 'Artist Name' folder, then that folder contains .flac files and an 'mp3' folder of the flacs converted to mp3. In 'Artist Name' folders which do contain an 'Album Name', the mp3 folder is located in each 'Album Name' subfolder. Here's what I want to do:

  1. Remove the .flac files from each folder (I don't need to save them).
  2. Move the files in the mp3 folder to the root folder.
  3. Remove the mp3 folder.

Is there a terminal command which will accomplish this? TIA for any assistance provided!

  • Hello. You could write a script to do this A single command in terminal I doubt. BTW All questions should always start with the version of Ubuntu being used.
    – David
    Apr 3, 2022 at 9:16

2 Answers 2


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/ \;

@David @Rinzwind, Thanks for responding. In Ubuntu 22.04 Beta, I copied the root folder containing the flacs to a temp directory and ran this executable script in this folder:

shopt -s globstar
for f in **/*.flac; do
   flac -cd "$f" | lame -b 320 - "${f%.*}".mp3 && rm "$f"

This operation deletes all flac files. Placing a # before the 'rm "$f" prevents deletion.

  • Since 22.04 does not exist hard to see how this is an answer.
    – David
    Apr 6, 2022 at 6:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .