#!/usr/bin/perl # # List files by modification date - youngest first. # Files are preceded by file date in YYYY.MM.DD HH:MM:SS format. # # Files can be given on the command line. Directories are traversed. # Symlinks are not followed. Default is current directory ("."). # Files can be supplied on standard input when first argument is "-". # # Example: # latest # latest . # latest ~/Backup # latest /etc/*.conf # latest /etc/inet /etc/netconf # ls | latest - # find ~ -type f -name "*.java" | latest - # # Matthias Gaertner - g@rtner.de - 04.04.2002 - Freeware - Version 1.0 $version = "1.0"; $date = "04.04.2002"; use File::Find; %h = (); if( !defined @ARGV ) { @ARGV = "."; } if( $ARGV[0] eq "-h" || $ARGV[0] eq "--help" || $ARGV[0] eq "-?") { usage(); } elsif( $ARGV[0] eq "-" ) { while(<>) { chomp; &wanted2( $_ ); } } else { find(\&wanted, @ARGV); } foreach $key ( sort { $h{$a} <=> $h{$b} } keys %h ) { ($sec,$min,$hour,$mday,$mon,$year) = localtime($h{$key}); $germandate = sprintf("%02u.%02u.%04u %02u:%02u:%02u", $mday, $mon + 1, $year + 1900, $hour, $min, $sec ); print "$germandate $key\n"; } sub wanted { return unless -f; my ($date) = (stat(_))[9]; $h{$File::Find::name} = $date; } sub wanted2 { return unless -f; my ($date) = (stat(_))[9]; $h{$_} = $date; } sub usage { print STDERR <