• Home
  • About Me
  • Welcome to Short Linux hints
Short hints about Linux


  • Tags

    hacking Linux linux cpanel courier maildir mailbox exim security viruses worms
  • Blogroll

    • Geany
    • Handy one-liners for sed
    • Linux By Example
    • Penguin Tutor

Oct 02

Calculating total file size with awk

Linux Add comments

Imagine you want to calculate the total size for all of your doc files. Here is a simple way to do it:

find -name '*.doc' -exec ls -al {} \; |awk '{SUM += $5} END {print SUM}'

What it does is find all the doc files, then pass them to the ls -al command through the exec option. Lastly awk takes the 5 column (the column for the file sizes), adds all the values and prints the result.

Comments are closed.

Powered by WordPress .::. Designed by SiteGround Web Hosting

cssandhtml