#!/usr/bin/perl -w my $rcsid = '$Id: mtime,v 1.1 2005/03/25 18:05:10 vogelke Exp $'; =head1 NAME mtime =head1 SYNOPSIS mtime -g file [file ...] mtime -s [list] mtime -v =head1 DESCRIPTION Get (or set) file modification times. =head1 OPTIONS -g read files on command line and print modtimes to stdout. -s read output from "-g" option and set times appropriately. -v prints the version and exits. =head1 AUTHOR Karl Vogel Sumaria Systems, Inc. =cut use strict; use subs qw(usage version); use File::Basename; my ($myname) = basename ($0, ".pl"); my ( $atime, $ctime, $dev, $file, $gid, $ino, $mode, $mtime, $nlink, $rdev, $size, $uid ); # # Command-line arguments. # @ARGV or usage("no args"); my $flag = 'get'; ARG: while (@ARGV) { $_ = shift @ARGV; /^-g/ and do { $flag = 'get'; next ARG; }; /^-s/ and do { $flag = 'set'; next ARG; }; /^-v/ and do { my $vers = version(); warn "$vers\n"; exit (0); }; /^-.*/ and do { usage ("unrecognized option: $_"); }; unshift(@ARGV, $_); last; } # # Get or set file access or modtimes. # if ($flag eq 'get') { foreach $file (@ARGV) { next unless -f $file; ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime ) = stat(_); print "$mtime $atime $file\n"; } } elsif ($flag eq 'set') { while (<>) { chomp; if (/(\d+) (\d+) (.*)/) { $mtime = $1; $atime = $2; $file = $3; utime( $atime, $mtime, $file ) || die "utime $file: $!\n"; } else { print STDERR "$_: messed-up line\n"; } } } exit(0); #--------------------------------------------------------------------- # Print a usage message from the comment header and exit. sub usage { my ($emsg) = @_; require Pod::Usage; import Pod::Usage qw(pod2usage); warn "$emsg\n"; pod2usage(-verbose => 1); } #--------------------------------------------------------------------- # Return the current version. sub version { $_ = $rcsid; s/,v / /; @_ = split; return "$_[1] v$_[2] $_[3] $_[4]"; }