1836872 Members
2164 Online
110110 Solutions
New Discussion

MTIME Command

 
Rajkumar_3
Regular Advisor

MTIME Command

Hai

How can we display the files which are older than 3 days?? suppose today is 17th ..
I want to display the files from 12th to 14th..

Is there any option in the FIND Command???

Can any one help me in this matter??

Regards
Rajkumar
Oracle DBA
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: MTIME Command

Let's say that you want all files that have been modified in the between 3 and 10 days in the past; i.e. those older than 2 days but younger than 10 days (and are regular files):

find . -type f -mtime +2 -a -mtime -11

Note: the -a (and) operator
If it ain't broke, I can fix that.
Rajkumar_3
Regular Advisor

Re: MTIME Command

Hai Clay,

Thank you for your reply..

I have a files in a /test directory.Todays date is 18th .Suppose i want to display the files which is older than 3 days..ie.,the files show display from 14th,13th,12th.

It should not use between those dates.......i mean there is no condition to display in between those dates..

dd/mm/yy File_names
----------------------------------
06/Oct/01 file06.cdr
07/Oct/01 file07.cdr
08/Oct/01 file08.cdr
09/Oct/01 file09.cdr
10/Oct/01 file10.cdr
11/Oct/01 file11.cdr
12/Oct/01 file12.cdr
13/Oct/01 file13.cdr
14/Oct/01 file14.cdr
15/Oct/01 file15.cdr
16/Oct/01 file16.cdr
17/Oct/01 file17.cdr
18/Oct/01 file18.cdr

Is it possible??

Thanks & Regards
Rajkumar
Oracle DBA
James R. Ferguson
Acclaimed Contributor

Re: MTIME Command

Hi:

The 'mtime' argument to 'find' operates on a 24-hour offset based on the current day and time. If you want more granulatory or a fixed window, create two reference files and use the '-newer' argument to 'find'. By example:

# touch -m -t 10120001 /tmp/ref1
# touch -m -t 10142359 /tmp/ref2
# find /tmp -type f -newer /tmp/myref1 -a ! -newer /tmp/myref2 -exec ls -l {} \;

This will find all files in the /tmp directory modified between 10/12 at 00:01 and 10/14 at 23:59, regardless of the current date and time.

Regards!

...JRF...
Rajkumar_3
Regular Advisor

Re: MTIME Command

Hai James,

Thank you for your reply..

Is it possible to display the files in hours based..
suppose if i enter the number 10 hours or 0.5 (that means 1/2 an hours) is should display the files like that along with the letter starting with "a"....

Is it possible??

Regards
Rajkumar
Oracle DBA
James R. Ferguson
Acclaimed Contributor

Re: MTIME Command

Hi:

If I understand your question correctly, then "no". The output from 'ls' shows dates and times in the format month, day-of-month and hh:mm unless the timestamp is older than 6-months. See the man pages for 'ls'.

BTW: It is a courtesy in this Forum to assign points to those who have helped you. In large part, this helps subsequent readers find answers and responses that helped solve a problem. Please see here for the official guidelines:

http://us-support.external.hp.com/estaff/bin/doc.pl/forward/screen=estaffAssistance/sid=927847dd187d8d7bbc?Page=file0002#forpoints

Regards!

...JRF...
Robin Wakefield
Honored Contributor

Re: MTIME Command

Hi Rajkumar,

I've put together a script which uses perl to give you the option of using find with a -older switch based on hours. All other arguments are treated as find arguments. So create the script:

========================================
#!/bin/ksh

args=$*
rest=$*
older=0
file=/tmp/tempfind.$$
echo $args |
grep -q -- "-older [^ ]*" && echo $args |
sed 's/\(.*\) -older \([^ ]*\)\(.*\)/\2 \1 \3/' |
read older rest
if [ $older -gt 0 ] ; then
perl -e '($sec,$min,$hour,$day,$mon,$year,$rest)=(localtime(time-$ARGV[0]*3600));
printf ("%04d%02d%02d%02d%02d.%02d\n",
$year+1900,$mon+1,$day,$hour,$min,$sec);' $older | read t
touch -m -t $t $file
rest="$rest ! -newer $file"
fi
find $rest
rm $file
======================================

Then you can issue something like:

./script.ksh /Database -type f -older 10.5 -mtime 8

to list any file older than 10.5 hours, but less than 8 days.

It's probably not foolproof, but may prove useful if you have perl loaded.

Rgds, Robin.