find out disk space used by certain type of files

It’s very easy to check how much does certain files occupied your hard disk space. I’m using this technique before moving my files to other host to estimate how long will it takes to do some transfer. We will use find command to do this (and some pipelining)

cd ./tmp           #move to desired directory where you want to check
find . -iname "*.mp3" -exec du -b {} + | awk '{total += $1} END {print total}'

What does it means?
the “find” command will search for all files matching (case-insensitive) pattern *.mp3 beginning from the current directory. For each file name found, do “du -b” on that file (it means: show the file size in bytes). Then “awk” will summarize all of the files size then at the end, show it to user. The total result would be in bytes.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>