Sat Dec 19 16:52:32 PST 2015

Removing Duplicated MP3 Music Directories

Occasionally, I have duplicated directories of mp3 file - for example when loading a second mp3 player with music. Then, later when trying to free up disk space, I have been unsure as to which directory to keep. This is complicated because mp3 files can have their headers updated which makes conventional 'diff' useless in determining whether files are identical. However, as noted yesterday, avconv can report the CRC signature of just the music, and you can use this to determine if two directories are really identical so that one can deleted.

I used two scripts to achive this. The first uses avconv to report the CRC of the supplied file. This is called, The second called uses the first script and simply collects the CRC values of the mp3 files below a supplied pair of directories. After collection the CRCs are diffed, and the user informed of the results.

Here are the scripts. First


export PATH=/opt/local/bin:/opt/local/sbin:$PATH

avconv -i "$1" -f crc - 2>/dev/null | grep CRC | awk '{print substr($1,5)}'



export PATH=/opt/local/bin:/opt/local/sbin:$PATH

#provide a simple recursive mp3 diff based on checksums

echo "Directory 1: $1"
echo "Directory 2: $2"

find "$1" -exec ~/bin/ {} \;  > /tmp/dir1.txt

find "$2" -exec ~/bin/ {} \;  > /tmp/dir2.txt

diff /tmp/dir1.txt /tmp/dir2.txt
if [ $ret -eq 0 ]
  echo "The directories are identical"
  echo "The directories are different"
  diff /tmp/dir1.txt /tmp/dir2.txt

Installing avconv on OS X involved following the instructions here:

Comments are closed

If you would like to get in touch with me, please mail zfs at

recent comments

Posted by ZFS | Permanent link | File under: bash
[StumbleUpon] [Digg] [Reddit] [Facebook] [Google]