Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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}'
share|improve this answer
    
This is genius, thanks. Added it as a function to my shell. –  Rob Feb 13 '12 at 13:25

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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