O'Reilly logo

Linux Server Hacks by Rob Flickenger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #62. Disk Age Analysis

Easily identify which parts of your disk change frequently

How can you quickly tell which parts of your filesystem are modified frequently and which haven't changed in months? It's very straightforward, with a proper application of Perl.

Here is a Perl script that will perform disk aging analysis on a filesystem. The program breaks down disk space two ways, by last modified date and last accessed date. A sample run looks like:

% diskage /usr/local

Disk aging analysis for /usr/local:

last num last num
Age (days) modified files accessed files
0 - 30 260403 Kb 817 140303 Kb 6968
31 - 60 11789 Kb 226 23140 Kb 199
61 - 90 40168 Kb 1126 1087585 Kb 31625
91 - 180 118927 Kb 995 0 Kb 0
181 - 365 85005 Kb 1889 0 Kb 0
366 - 9999 734735 Kb 33739 0 Kb 0
----------- ----- ----------- -----
Total 1251029 Kb 38792 1251029 Kb 38792

You can run the script with the -v option to list the last modified and last accessed days for every file in the filesystem.

Listing: diskage

#!/usr/local/bin/perl # # Disk aging report generator # Written by Seann Herdejurgen # # May 1998 use File::Find; # Initialize variables @levels=(30,60,90,180,365,9999); # Check for verbose flag if ($ARGV[0] eq "-v") { $verbose++; shift(@ARGV); } $ARGV[0]=$ENV{'PWD'} if ($ARGV[0] eq ""); foreach $dir (@ARGV) { foreach $level (@levels) { $modified{$level}=0; $accessed{$level}=0; $mfiles{$level}=0; $afiles{$level}=0; } print("\nDisk aging analysis for $dir:\n\n"); print (" mod acc size file\n") if ($verbose); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required