perl -e '@q=stat($ARGV[0]); print time-$q[9]' file1
ls -ltr
#!/usr/bin/perl
#^ PROGRAM DESCRIPTION
#^ -------------------
#^ This program prints the modification times and names of files.
#^ It uses the following format: inodetime.pl filename
#^ It will accept: inodetime.pl filename1 filename2 filename3
#^ inodetime.pl /tmp/file*
#^ The format of the output is: YYYYMMDDhhmmss filename
#^ example:
#^ $ inodetime.pl /tmp/t*
#^ 19961115105425 /tmp/test.sql
#^ 19970116113616 /tmp/tststat.pl
#^
#^###################################################################
# Get the (next) input from the command line
while ($curfile = $ARGV[0])
{
# Do following code block only if $curfile exists
if (-e $curfile)
{
# stat structure into variables
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat("$curfile");
# time structure into variables
local($sec,$min,$hr,$day,$mon,$yr,$wday,@dntcare) = localtime($mtime);
$yr = ($yr>=70) ? $yr+1900 : $yr+2000;
$yr="$yr";
$mon = (++$mon < 10) ? "0$mon" : "$mon";
$day = ($day < 10) ? "0$day" : "$day";
$hr = ($hr < 10) ? "0$hr" : "$hr";
$min = ($min < 10) ? "0$min" : "$min";
$sec = ($sec < 10) ? "0$sec" : "$sec";
# Rearrange in the YYYYMMDDhhmmss format and assign to $dte variable
$dte = join('',$yr,$mon,$day,$hr,$min,$sec);
# Print modification date and filename
print ("$dte $curfile\n");
}
# Shift to next position in command line
shift (@ARGV);
}
#! /usr/bin/ksh
typeset -Z2 d m
Jan=1 Feb=2 Mar=3 Apr=4 May=5 Jun=6 Jul=7 Aug=8 Sep=9 Oct=10 Nov=11 Dec=12
date "+%Y %m" | read year month
for i ; do
line=$(ls -dl $i)
line=${line##+([! ])+([ ])}
line=${line##+([! ])+([ ])}
line=${line##+([! ])+([ ])}
line=${line##+([! ])+([ ])}
line=${line##+([! ])+([ ])}
set -A stamp $line
d=${stamp[1]}
eval m=\$${stamp[0]}
y=${stamp[2]}
((${#y} != 4)) && ((y=year-(m>month)))
echo $y $m $d $i
done
exit 0
Wednesday, February 18, 2009
PERL Script for getting "Timestamps" -Files Creation Time
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment