Linux Remove directories that do not contain music files
#1
Thought I'd leave this here for anyone looking to clean up an MP3 collection. I was finally ready to move to a clean Eden install for 4 boxes and wanted my music collection as clean as possible.

My directories are like this:
/media/music/artist/album/files

The problem was that a large number (>1200) of orphaned directories with album names were cluttering my file view. I finally got the below script to remove directories that did not contain any music files. Hopefully, this can save folks some time since I had some issues finding an example.

*Please test this script to make sure it behaves like you think*

Code:
#!/bin/bash

    IFS=$'\n'
    for dirs in $(find . -type d); do
        FC=$(find "$dirs" -type f -iname "*.aac" -or -iname "*.mp3" -or -iname "*.mp4" -or -iname "*.flac" | wc -l)
        if [ $FC == "0" ]; then
            echo "*** $dirs"
           rm -rf  "$dirs"
        fi
    done
Reply

Logout Mark Read Team Forum Stats Members Help
Remove directories that do not contain music files0