Is your (Unix/Linux) filesystem getting full and you wonder whether removing some old log files would help? Use this one-liner to find out how much space would be freed:

find /opt/app/logs -iname "*log*" -type f -mtime +30 | perl -lne '$sum + += (stat)[7] }{ print $sum'
It's nice to be important, but it's more important to be nice. -- Tommy

Replies are listed 'Best First'.
Re: How much disk space would be freed?
by Anonymous Monk on Feb 21, 2017 at 20:07 UTC
    use File::Find::Rule 'rule'; use File::stat; use List::Util 'sum'; print sum( map {stat($_)->size} rule->file->name(qr/log/i) ->mtime("<".(time-30*24*60*60)) ->in("/opt/app/logs") ), "\n";
    Not exactly the same because find rounds mtimes. I wish importing stuff didn't take so many characters :-)

      Yeah, for me the coolness of my solution is in the fact that it's a one-liner. Thus I can quickly copy/paste it to the shell of any of my servers and see the results. And I forgot to thank Discipulus for recommending the eskimo operator :-).

      Il nostro corpo e il buon cane che guida il cieco. -- L. Sciascia