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.

1 Comment

  1. Just what I need. Thank you !

Leave a Reply

Your email address will not be published.

*

© 2019 Thinkway

Theme by Anders NorénUp ↑