The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 12-21-2005
Registered User
 

Join Date: Dec 2005
Posts: 3
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
Reply With Quote
Forum Sponsor
  #2  
Old 12-21-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,269
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);
}
Reply With Quote
  #3  
Old 12-21-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Time in seconds since a file was last modified...
Code:
perl -e '@q=stat($ARGV[0]); print time-$q[9]' file1
Reply With Quote
  #4  
Old 12-22-2005
Registered User
 

Join Date: Dec 2005
Posts: 3
just what i needed! Thanks a lot to you both
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0