Deleting all files recursively from directories while ignoring one file type

Hi,

Seems like I need help again with a problem:

I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders
except for .mp3 and .MP3 files.

I tried it with globalignoring mp3 files, finding and deleting all other files, which
resulted in all files in the Music Dir to get deleted leaving me with empty dirs.

Thanks in advance for any help

find Music -type f  \( ! -name '*MP3' -a ! -name '*mp3' \) -exec rm {} \;
1 Like

Try this...

find . ! -wholename "*.mp3" ! -wholename "*.MP3" -delete

--ahamed

1 Like

ahamed101: Awesome ! Works just like it should :slight_smile: Thanks !
( would adding more filetypes to be ignored as easy as adding other "! -wholename "*.xxx"" or is there a limit as to how many filetypes can be ignored ?)

@jim mcnamara: Also thanks, every solution you have, might turn out to be useful in the future :wink:

Say, do you by any chance know a solution to my other problem ?: