Index syndication
comment syndication

awk oneliner to find large files

March 20, 2009 at 16:48 · Filed under unix

A mega geeky awk one-liner today. Tested on Solaris under bash, so YMMV.

Have you ever found that a filesystem is filling up fast, and dont know what is causing it? This one liner (which can be placed in a cron job if you like) is best run as a super user.

It will:

  1. Search for all files in the current dir and subdirs that are modified in the last 3 days;
  2. list them, filtering just the filesize and name/path;
  3. sort/order by the largest file; and
  4. Email you a copy of the report.
 find / -type f -mtime -3 -exec ls -l {} \; 2>/dev/null \
| awk '{print $5 " " $9}' \
| awk '{printf "%12d\t%s\n", $1, substr($0,index($0,$2),80)}' \
| sort -r >/tmp/largefiles.txt && \
( uuencode /tmp/largefiles.txt largefiles.txt ) \
| mailx -s 'Large Files Report' -r mail2@youremail.com `cat /tmp/mailrecipients` &

Nice. If you just want to see the response on stdout then try this:

 find / -type f -mtime -3 -exec ls -l {} \; 2>/dev/null \
| awk '{print $5 " " $9}' \
| awk '{printf "%12d\t%s\n", $1, substr($0,index($0,$2),80)}' \
| sort -r

Have fun.

Alphin Johnson said,

March 25, 2009 @ 18:04

Nice

lantrix said,

March 26, 2009 @ 10:48

Thanks. Hey long time no speak. We should catch up!

RSS feed for comments on this post · TrackBack URI

Leave a Comment