#!/usr/bin/perl -w # (C) 2003-2007 Willem Jan Hengeveld # Web: http://www.xs4all.nl/~itsme/ # http://wiki.xda-developers.com/ # # $Id: lstm 1706 2008-02-25 15:34:00Z itsme $ # use strict; # list all timestampts assosiated with a file. use Time::Local; use Getopt::Long; use POSIX; # time - 86400 * -A $fn == atime == dir /ta # time - 86400 * -M $fn == mtime == dir /tw ** default # time - 86400 * -C $fn == ctime == dir /tc my $g_rate; my $g_mtime; my $g_atime; my $g_ctime; sub usage { return <<__EOF__; Usage: lstm [options] [files] -mt show inode modification time -at show last access time -ct show creation time -t0 specify starttime -r show growth rate __EOF__ } my $t0; GetOptions( "mt"=>\$g_mtime, "at"=>\$g_atime, "ct"=>\$g_ctime, "t0=s"=>sub { $t0=parsetime($_[1]); }, "tnow"=>sub { $t0=time(); }, "r"=>\$g_rate, ) or die usage(); if (!defined $g_rate && !defined $g_mtime && !defined $g_atime && !defined $g_ctime) { $g_mtime= $g_atime= $g_ctime = 1; } elsif (defined $g_rate && !defined $g_mtime && !defined $g_atime && !defined $g_ctime) { $g_mtime= 1; $g_atime= $g_ctime = 0; } $g_rate ||= 0; printheader(); for my $filename (@ARGV) { $filename .= "/" if ( -d $filename && $filename !~ m{/$}); if (my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks)= stat $filename) { my @items; push @items, timestr($atime) if ($g_atime); push @items, timestr($mtime) if ($g_mtime); push @items, timestr($ctime) if ($g_ctime); push @items, sprintf("%10d", $size); # todo: use 'now' instead of atime if ($g_rate) { push @items, sprintf("%8d", $mtime>=($t0||$atime)?0:$size/(($t0||$atime)-$mtime)); } push @items, $filename; print join(", ", @items), "\n"; } else { warn "$filename: $!\n"; } } sub timestr { return POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime shift); } sub printheader { my @list; push @list, ".atime" if ($g_atime); push @list, ".mtime" if ($g_mtime); push @list, ".ctime" if ($g_ctime); push @list, ".size"; push @list, ".rate" if ($g_rate); push @list, ".filename"; print join(", ", @list), "\n"; } sub parsetime { my @t= reverse split m{[-/ :]+}, $_[0]; $t[4]-=1; $t[5]-=1900; return POSIX::mktime @t; }