![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| override the system date-timestamp on the Unix servers | DavidH | UNIX for Dummies Questions & Answers | 5 | 09-27-2007 07:05 AM |
| vmstat output with date & timestamp | luft | UNIX for Dummies Questions & Answers | 9 | 11-16-2006 07:49 AM |
| getting date from timestamp | pavan_test | UNIX for Dummies Questions & Answers | 2 | 09-28-2006 09:01 AM |
| how to convert from timestamp to date format in tcsh | umen | Shell Programming and Scripting | 2 | 11-22-2005 01:51 AM |
| Creating file with date/timestamp in it | ccpjr29 | Shell Programming and Scripting | 7 | 03-04-2002 01:14 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
get a file date/timestamp
Could someone tell me how to get the date/time (to the second) a file was last modified? I need to know if a file was modified in the last 30 seconds from the system date. I'm on AIX/unix 4.3
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
#!/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);
}
|
|
#3
|
||||
|
||||
|
Time in seconds since a file was last modified...
Code:
perl -e '@q=stat($ARGV[0]); print time-$q[9]' file1 |
|
#4
|
|||
|
|||
|
just what i needed! Thanks a lot to you both
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|