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

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

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.