Find sum of file sizes listed in ls -l using awk

por | 6 septiembre, 2014

1
ls -l | awk '{ TOTAL += $5} END { print TOTAL/1024/1024 }'

With this, awk will pull field number 5 from ls -l, which is the size in bytes in most of the *nix platforms.

Then for each occurrence add to the variable TOTAL. At “END”, it will divide TOTAL by 1024*1024 ( bytes to MB) and print