Use awk to calculate total size of files – part 1

Your boss came to you and asked for total size of files which has not been accessed for more than 30 days! Assume that you are just checking for 1 directory “/abc” . Here comes the simple command:

find /abc -atime +30 -exec ls -lk ‘{}’ \;  | awk ‘{SUM += $5} END {print SUM} ‘

Explaination:

find /abc -atime +30 -exec ls -lk ‘{}’ \

find command will find /abc and check for accestime which has not been access for 30 days and list it out the result

awk ‘{SUM += $5} END {print SUM} ‘

awk will sum all the result then only print out final figure.

The command is extremely useful especially you have multiple of directory residing in /abc :

/abc/123

/abc/456

/abc/789

Just write a simple script to generate it! I will cover this on next post.

Posted in Linux | Tagged , , | 1 Comment

One Response to Use awk to calculate total size of files – part 1

  1. Geac Papatel says:

    Just what I need. Thank you !

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">