Re: oldest file in a filesystem

From: Fred.Bateman@usdoj.gov
Date: Fri Apr 30 2004 - 06:23:13 EDT


This uses Perl. It prints all information for files
recursively like "find" but prints the three timestamps
for a file in a consistent format. You should be able to
use this script and sort the output on the date/time fields
to get what you need.

#! /usr/bin/perl -w
# Input:
# Directory name - default == current directory.
#
# Output:
# One line for each file/directory with all fields returned from stat

use strict;
use File::Find;

my $fileName; # file name

@ARGV = ('.') unless @ARGV; # default to current directory if none provided

find(\&printFileStat, @ARGV); # call find - pass callback address and directory name

exit; # return to caller

# **********************************************************************
# the following routine is called by the File::Find package.
# it is called once for each file.

sub printFileStat
{
   my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks);
   my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);

   $fileName = $File::Find::name; # retrieve filename from the package

# get file information
   ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = lstat($fileName);

# check if we received anything
   if (!defined($dev))
   {
      print "undefined for: $fileName\n";
      return;
   }

# format/print $dev
   printf "%d ", $dev;

# format/print $ino
   printf "%6d ", $ino;

# format/print $permissions
   printf "%6o ", $mode;

# format/print $nlink
   printf "%2d ", $nlink;

# format/print $uid
   printf "%5d ", $uid;

# format/print $gid
   printf "%5d ", $gid;

# format/print $rdev
   printf "%10d ", $rdev;

# format/print $size
   printf "%8d ", $size;

# format/print atime
   ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($atime);
   printf "%4d/%02d/%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec;

# format/print mtime
   ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($mtime);
   printf "%4d/%02d/%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec;

# format/print ctime
   ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($ctime);
   printf "%4d/%02d/%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec;

# format/print $blksize
   printf "%5d ", $blksize;

# format/print $blocks
   printf "%5d ", $blocks;

# format/print filename
   printf "%s\n", $fileName;

   return; # return from printFileStat
}

-----Original Message-----
From: aix-l@Princeton.EDU [mailto:aix-l@Princeton.EDU]On Behalf Of
DTaylor@WBMI.COM
Sent: Thursday, April 29, 2004 9:53 AM
To: aix-l@Princeton.EDU
Subject: oldest file in a filesystem
Importance: Low

Hi *

I am trying to trouble-shoot a problem with cache-corruption on an
imaging system. It would be very helpful if I could locate the oldest
file (modified or created) in that cache. Does anyone know of a script
that would do this? The cache is about 35GB in size and the average
file size is ~ 100K.

The corruption is definitely application-related. We would just like to
pinpoint the point in time that it began in order to discover the root
cause.

TIA

David Taylor

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:52 EDT