The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unzip files where modified time>05:00 ? SunnyK Shell Programming and Scripting 3 11-06-2007 06:15 AM
Finding files which are modified few mins ago rajus19 Shell Programming and Scripting 3 08-16-2007 05:32 AM
Finding list of modified files for a particular time duration sanajyg_mnit SUN Solaris 2 02-12-2007 11:48 PM
Finding modified files rhayabusa UNIX for Dummies Questions & Answers 2 12-16-2004 09:48 AM
Checking modified time of files am97395331 UNIX for Dummies Questions & Answers 4 07-02-2003 07:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: May 2005
Posts: 14
Stumble this Post!
Finding out the last modified time for files

I need to find out the last modified time for the files which are older than 6 months. If I use ls -l, the files which are older than 6 months, I am just getting the day, month and year instead of exact time. I am using Korn shell, and SUN OS.

Thanks in Advance,
Kiran
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-18-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,660
Stumble this Post!
If you have stat on your machine, you can use that.

From man stat

Code:
       The valid format sequences for files (without --filesystem):

 %X - Time of last access as seconds since Epoch %x -  Time
              of  last  access %Y - Time of last modification as seconds since
              Epoch %y - Time of last modification %Z - Time of last change as
              seconds since Epoch %z - Time of last change

There is another way out as well. Use the approach given in this post - script to view files based on date

vino
Reply With Quote
  #3 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: Jul 2005
Location: Mt. Prospect, Illinois
Posts: 32
Stumble this Post!
Finding out the last modified time for File access etc.

Kumariak,
I would suggest using a version of the "find" command. I suggest a man page is a good place to start, i.e. man find<cr>.


regards
Reply With Quote
  #4 (permalink)  
Old 10-18-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,845
Stumble this Post!
Otherwise you'll have to use perl or something similar to get a full filetime - this gets the mtime of the file:
Code:
#!/usr/bin/perl
#^ PROGRAM DESCRIPTION
#^ -------------------
#^ This program prints the modification times 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:
#^           $ filetime.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\n");
      }

   # Shift to next position in command line

   shift (@ARGV);
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:20 AM.


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

Content Relevant URLs by vBSEO 3.2.0