Linux – Find and remove audio files which has less than 3 minutes of play duration

audiofindlinux

Is there a way to find and delete all the audio files recursively (MP3 files) which have less than 3 minutes play duration time?

Consider the situation that I have mixture of multiple format files (e.g. directories, text files and mp3 files).

Best Answer

Here's one way. Run mediainfo against every mp3 file, if shorter than 3 minutes, delete it.

#!/bin/bash
for FILE in $(find . -type f -name \*.mp3); do
    [[ $(mediainfo --Output='Audio;%Duration%' "${FILE}") -lt "180000" ]] && rm "${FILE}"
done

Or for fans of one-liners:

find . -type f -name \*.mp3 -exec bash -c '[[ $(mediainfo --Output="Audio;%Duration%" $1) -lt "180000" ]] && rm "$1"' -- {} \;
Related Question