Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently, I converted my music files to a different format. I have for example a folder of an artist containing the different albums in separate folders. I would knowing if is there a way to delete *.mp3 files in all my album folders of an artist using a simple command? For example, if I use ~music/artist_a/album1$rm *.mp3 it delete all the mp3 files of only the folder album1, but I want to use a command that delete all the mp3's of album1, album2,... in the artist_a folder.


share|improve this question
I would be very interested in an answer myself. Surprisingly, the -r option for rm only removes files in the top-level directory. – Christopher Kyle Horton Dec 3 '11 at 6:56
Jeje, I try to use, for example ´rm -r *.mp3´ but it's BAD X) – Brallan Aguilar Dec 3 '11 at 7:02
@WarriorIng64: given that the * expansion is done by the shell, rm only see a list of names, and delete them. If one of these names is a directory, the -r would indicate to remove the whole directory. – enzotib Dec 3 '11 at 7:03
up vote 8 down vote accepted

If you go one level up, you can do:

~music/artist_a/album1$ cd ..
~music/artist_a$ rm */*.mp3

to delete mp3s from every directory inside the current. If you want to delete only from specific subdirectories:

~music/artist_a$ rm {album1,album2,album4}/*.mp3

You can also use find to delete all mp3 in subfolders of every level

~music/artist_a$ find . -iname '*.mp3' -delete

Use these command with caution.

share|improve this answer
Excellent information! All works OK. Thank you very much! – Brallan Aguilar Dec 3 '11 at 6:59

An alternative method you could use would be

find ~music/artist_a -name \*.mp3 -exec rm {} \;


share|improve this answer
Mmm an alternative form. I'll try it! Thanks – Brallan Aguilar Dec 3 '11 at 7:09
I found this solution is better if you want to delete files into a indefinite number of directories. It's a excellent solution and more general. – Brallan Aguilar Dec 3 '11 at 10:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.