My ~/Music/
directory is actually full of "empty" directories I want to clean. I say "empty" because this directories actually contain files, some contain old cover image files or Thumbs.db files
.
I want to recursively delete all of these directories that don't contain any music files inside or other directories inside.
For example ~/Music/Audioslave/ contains a lot of directories with album names and no music files, but I don't want to delete it because inside there are the music files. I want though to delete ~/Music/Audioslave/oldalbum/ if the oldalbum directory doesn't have nor music files nor other directories inside.
Best Answer
I found this example on SO, titled: Terminal - Delete All Folders Not Conatining .mp3 Files.
Example
Sample data.
Sample run
If I were to run it it would delete the following:
Other file types
You can simply extend this by adding more
-name
arguments to the 2nd find command in the script. Example, to add.wav
files:That says
*.mp3
OR*.wav
. To add more or others:I'm sure this block could be condensed if you had a lot more file types using alternative switching to
find
.