Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How much disk space would be freed?

by reisinge (Hermit)
on Feb 21, 2017 at 09:41 UTC ( [id://1182412]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1182412]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found