App-lasttouch
view release on metacpan or search on metacpan
#!/usr/bin/perl
use 5.014 ; use strict ; use warnings ;
use File::Find ;
use Time::HiRes qw[ stat tv_interval time gettimeofday ] ;
use Getopt::Std ;
#use Getopt::Long qw [ GetOptions :config bundling no_ignore_case pass_through ] ; # GetOptionsFromArray ] ;
use Term::ANSIColor qw[ :constants ] ; $Term::ANSIColor::AUTORESET = 1 ;
use Pod::Perldoc ;
use POSIX qw { strftime } ;
use feature qw[ say ] ;
my $start_time = [ gettimeofday ] ;
my %o ;
getopts '1,:acd:g:',\%o ;
$o{d} //= 1 ; # ãã£ã¬ãã¯ãªã«å¯¾ããå¦çãæå¶ãããã©ããã0ãæç¤ºçã«ä¸ãããããæå¶ã
$o{g} //= 12 ; # æè¿ã¢ã¯ã»ã¹ããããã¡ã¤ã«ãæå¤§ä½ååãåºãã
my $sf = $o{a} ? 8 : $o{c} ? 10 : 9 ; # stat ã§è¿ãããé
åã®ä½çªç®ãã¿ããã 9 ã¯å¤æ´æå»ã
my @ Files = () ;
main () ; exit 0 ;
sub wanted {
my @s = stat $_ ;
my $xtime = $s[ $sf ] ; # 8 㯠atime, 9 㯠mtime, 10 㯠ctime
my $bytes = $s[ 7 ] ;
push @ Files , App::lasttouch::fileinfo -> new ( $_ , $xtime, $bytes ) if ! ( -d _ && do { $_.='/' ;1} ) || $o{d} ;
}
sub main {
my @sdir = @ARGV ? @ARGV : qw[ . ] ;
find ( { wanted => \& wanted , no_chdir => 1 } , @sdir ) ;
my $now = time ;
$_ -> { elapsed } = $now - $_->{xtime} for @Files ; # æ°ããªè¦ç´ ãã追å ãã¦ããã
@ Files = sort { $a ->{elapsed} <=> $b->{elapsed} } @Files ;
say join "\t", "diff_seconds", "sec_before", $o{1} ? 'date_time' : () , "byte_size", "file_name" ;
my $mrec0 = 0 ;
my $shown = 0 ;
for ( splice @Files , 0 , $o{g} ) {
my @t ;
my $mrec = $_->{elapsed} ;
push @t , sprintf "%0.6f" , $mrec - $mrec0 ;
push @t , sprintf "%0.6f" , $mrec ;
push @t , strftime '%Y-%m-%d %H:%M:%S' , localtime $_ -> {xtime} if $o{1} ;
push @t , $_ -> {bytes}, $_ -> {name} ;
$t[-2] =~ s/(?<=\d)(?=(\d\d\d)+($|\D))/,/g if $o{','} // '' ne "0" ;
say join "\t" , @t ;
$shown ++ ;
$mrec0 = $mrec ;
}
my $num = @ Files ;
my $elps = sprintf "%.6f" , tv_interval $start_time ;
say STDERR CYAN "Files processed : $num ; Shown above : $shown ; Elapsed seconds : $elps" ;
}
sub HELP_MESSAGE { # <-- - ãµãã³ãã³ããå¼ã°ãã¦ããã¨ãã¯ãã®ãã«ããå¼ã°ããã
local @ARGV = do { my ($x,@y) = 0 ; 1 while ( @y = caller $x++ )[ 0 ] eq "Getopt::Std" ; $y[1] } ;
Pod::Perldoc -> run ;
}
sub VERSION_MESSAGE { $ Getopt::Std::STANDARD_HELP_VERSION = 1 } ;
package App::lasttouch::fileinfo ;
sub new ( $ ) { #say 1 ;
my $ins = { name => $_[1] , xtime => $_[2] , bytes => $_[3] } ;
return bless $ins ;
}
=encoding utf8
=head1 NAME
lastaccess DIRNAME
DIRNAMEã®ä¸ã«ãããã¡ã¤ã«ã§ãæå¾ã«å¤æ´ãããé ã«ãã¡ã¤ã«ã表示ããã
ãªãã·ã§ã³:
-a : åãã¡ã¤ã«ã®å¤æ´æ¥æã§ã¯ãªãã¦ãã¢ã¯ã»ã¹ãããæ¥æ(atime)ãè¦ãã
-c : åãã¡ã¤ã«ã®å¤æ´æ¥æã§ã¯ãªãã¦ã使ãããæ¥æ(ctime)ãè¦ãã
-d 0 : éä¸ã§ç¾ãããã£ã¬ã¯ããªã«å¯¾ããå¦çãæå¶ããã
-g N : æå¤§æè¿ã®ä½åãåãåºããã®æå®ãæªæå®ãªã12ã
-1 : æ¥ææ
å ±ã YYYY-MM-DD HH:MM:SS ã®å½¢å¼ã§ä¸ããã
-, 0 : 3æ¡åºåãã®ã³ã³ããæå¶ããã
éçºã¡ã¢ :
* æ·±ãé層㯠--maxdepth ãªã©ã§å¶éãå ããããã¾ãã-.0 ã®ãããªããªãªããã¡ã¤ã«ã追ããããªããªãã·ã§ã³ãå ãããã
=cut
( run in 1.923 second using v1.01-cache-2.11-cpan-ad19def0cd9 )