Skip to main content

CLI Tricks: Compare directory sizes when hard-linking

I have directories with lots of image files (or mail files), some of which I hard-link into other directories to save space or make sure they're in sync. How much space am I saving by hard-linking?

(du -sl ; printf '-\n' ; du -s) | awk '{print $1}' | paste -s - | bc

With a little math, most of it can happen in one awk statement:

(du -sl ; du -s) | awk '{t+=(-NR*2+3)*$1} END{print t}'