Assuming you want to delete non-mp3 files anywhere under a specific directory (which I assume is the current directory), and that they are all called names ending in .mp3
, the following should work.
find . -type f \! -name \*.mp3 -exec rm {} \;
A simpler way, pointed out in a comment below (thanks, @DanielBeck!), would be to use the -delete
option instead.
find . -type f \! -name \*.mp3 -delete
This finds all ordinary files (-type f
) whose name does not (\!
) match the pattern *.mp3
, then deletes them (-exec rm {} \;
, or the rather simpler -delete
option).
Thanks Daniel, I didnt know the trick with the option-click ;) But it also shows me the folders - any way to exclude them as well? or another possibility would be to have a bar on top to sort the results by type or date or name, etc... – stoobz – 2014-06-17T21:05:40.013
@stoobz: Just add another line to the
None
block that excludes theKind
Folder
… – Daniel Beck – 2014-06-17T21:15:26.303