My first goal when coding is usually to make it work and then clean up the code into a more maintainable format.  Many people prefer to keep code clean from start to finish but thinking “maintenance first” slows me down — I like to GO GO GO!  Sometimes making code means the code size gets larger, sometimes it means getting smaller.

Oftentimes when I’m trying to abstract my CSS preprocessing code (Stylus), I abstract my mixins but want end up with the exact same CSS output.  What’s the easiest way to check that the outcome is likely the same, without scouring the site and checking every section?  Checking the output directory size.  If the CSS code is the same size before and after changes, we’re golden!  So how do we check directory size?

du -s 		# 16075464, recursive
du -sh 		# 7.7G, recursive, human readable

The commands above provide the directory size in different formats.  If you want to get the exact byte size of a directory, you can execute this slightly more complicated command:

find . -type f -exec ls -l {} ; | awk '{sum += $5} END {print sum}' # 8209358267

Of course something flukey could happen and the CSS change with the exact same size coming out, but this method isn’t meant to be scientific.  And remember that these commands can be used for any number of purposes!

Source: David Walsh

Leave a Reply