Saturday, March 31, 2007

Linux: How many songs do I have

I have always wanted to know the exact number of music files that I own. Of course Amarok appears to have the correct answer, still I always wanted to write something like that

#!/bin/bash
# Count the music files starting form MUSIC_BASE
# Thanassis Bakalidis
# 31-03-2007

# This is the directory containing all my music
MUSIC_BASE=/mnt/Culture/My\ Mjavascript:void(0)usic
# Add more music file extentions here
MUSIC_EXTENTIONS="mp3 wma ogg flac"

echo Base directory is $MUSIC_BASE

TOTAL_FILES=0
for ext in $MUSIC_EXTENTIONS
do
echo ""
echo Saerching for $ext files
current=`find "$MUSIC_BASE" -type f -name "*.$ext" -print | wc -l`
echo Located $current $ext files
TOTAL_FILES=`expr $TOTAL_FILES + $current`
done

echo ""
echo A total of $TOTAL_FILES music files were accounted.
exit

0 comments:

Post a Comment