I have a samba share with my music on it, and I'd like to find out how much disk space only the mp3 files (not anything mixed in with my music like pictures or videos, or any other filetypes like flac or aac or ogg) are taking up. I've tried baobab, gdmap, and ncdu, and don't really want to basically install all of KDE to try filelight (which doesn't look like it can do this either).

I can get a big list of what all is going to move (find ~/moremusic -name "*.mp3"), but AFAIK that's not totally helpful. If I do something like du -a ~/moremusic | grep ".mp3" I get a whole big list that each line starts with the filesize in KB. Just have to have that added up and I'll be good to go, but I have no idea the best way to do that.

link|improve this question

feedback

2 Answers

up vote 2 down vote accepted

With bash 4.x

shopt -s globstar; du **/*.mp3 | awk '{sum+=$1}END{print sum}'

With find

find . -type f -name "*.mp3" -exec du {} + | awk '{sum+=$1}END{print sum}'
link|improve this answer
This is genius, thanks. Added it as a function to my shell. – Rob Feb 13 at 13:25
feedback

Gives the total size in bytes:

echo $(($(find ~/moremusic -name "*.mp3" -printf %s+)0))

Uses find to create a string of separate byte sizes ending with "+". This string, with an ending "0" to keep the shell from complaining about an empty operator, is given to the built-in shell calculator function.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.