Find all Files of a Type and Count the Size Together

23 September 2008
by Gavin Colborne

This wonderful little tool written by Richard Aldridge uses ‘sed’ to group together all the files under a particular folder of a certain type (in the example this is files whose name contains the string ‘local’ but you could easily change this to look for other groups of files such as ‘.log’ or ‘.html’ files) and then adds all their sizes up to give a total number of kb the files amount too.

find . -name '*local*' -ls | awk 'BEGIN {$count=0} /./ {$count += $7} END {print $count}'

Our Latest News