![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
||||
|
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 |
|
|||
|
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);
}
|
|||
| Google The UNIX and Linux Forums |