Linux – Show file size by type in Linux


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.


Best Answer

You can use du:

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

output example: