up vote 0 down vote favorite
share [g+] share [fb]

I'm trying to find out the total size of all files within a directory that have a particular extension.

I do some offsite backup via rsync but due to limited bandwidth and disk space at the other end I can't do everything, so I'd like to find out, for example, how much disk space MP3 files take up so I can decide whether to remove the mp3 extension from the current list of rsync excluded patterns.

It's not as simple as doing a 'du -sh' on the My Music directory in there as there's some other file types.

Thanks!

link|improve this question
feedback

3 Answers

I just tried the following

find Music/ -name '*.mp3' -exec ls -l {} \; | awk '{ SUM += $5} END { print SUM/1024/1024 }'

And got the correct answer in Megabytes (1024 x 1024)

link|improve this answer
Right on, works great. – Jeffrey Vandenborne Dec 26 '09 at 23:44
feedback
find Music/ -iname "*.mp3" -type f -exec stat -c "%s" {} \; | awk '{SUM+=$0} END {print SUM/1024/1024}'

Got the correct answer as well, exactly the same as pavium's solution, could be a bit more reliable though.

link|improve this answer
feedback

You can use du:

find Music/ -type f -name "*.mp3" -exec du -shc {} + | tail -1 | awk '{print $1}'

output example:

980M
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.