SUMMARY: Finding files that are older than a number of hours rath er than a number of days

From: Williams, David J <David.J.Williams_at_au.faulding.com>
Date: Tue, 04 Jan 2000 11:28:55 +1030

On Fri 31/12/1999 14:39 I wrote:

                I would like to know if anyone has an easy way of finding
files that are older than a number of hours, for example, 2 hours.

                The find command will only work against a number of days,
for example,
                find /var/adm/syslog.dated -depth -type d -ctime +5 -exec rm
-rf {} \ ;

                Please respond directly to me and I will summarise.

                Thanks in advance,

                David

                David J Williams
                Technical Specialist
                Information Services
                F H Faulding & Co Limited
                Tel: +61 8 8408 3450/ Fax: +61 8 8408 3500
                mailto:david.j.williams_at_au.faulding.com
<mailto:david.j.williams_at_au.faulding.com>
                http:www.faulding.com

Below are all the responses I received. Thankyou to all who replied and for
replying so quickly.

And as Andrea Paolini said, Happy New Year.

David

David J Williams
Technical Specialist
Information Services
F H Faulding & Co Limited
Tel: +61 8 8408 3450/ Fax: +61 8 8408 3500
mailto:david.j.williams_at_au.faulding.com
<mailto:david.j.williams_at_au.faulding.com>
http:www.faulding.com


****************************************************************************
***********************************


Find a file that is 2 hours old or touch one:
touch MMDDhhmm timestamp (where hh = current_hour - 2)
touch 12302120 timestamp
find /wherever ! -newer timestamp
-----------------------------------------------------------------------
Sean O'Connell Email: sean_at_stat.Duke.EDU
<mailto:sean_at_stat.Duke.EDU>
Institute of Statistics and Decision Sciences Phone: (919) 684-5419
Duke University Fax: (919) 684-8594


****************************************************************************
***********************************


Using gnu find.
|=================================================
| Cai, Xuejun
| Tel: (+86-10) 68236038(o) 68244467(h)
! http://alpha01.ihep.ac.cn/~caixj <http://alpha01.ihep.ac.cn/~caixj>
| Pager: (+86) 198 call 10015237
| Public PGP key:
| http://alpha01.ihep.ac.cn/~caixj/DSSkey.txt
<http://alpha01.ihep.ac.cn/~caixj/DSSkey.txt>
|=================================================
& Linux Is Not just gnU and uniX &


****************************************************************************
***********************************


Suppose you want to find a file that someone was editing during lunch break
on Wednesday (three days ago). Rather than examining the entire list of
files modified three days ago with the -mtime 3 option, you can create two
empty files: /tmp/before, whose modification time is before the user began
lunch on Wednesday, and /tmp/after, whose modification time is after lunch
was finished. Then you can tell find to locate all the files newer than
/tmp/before, but not newer than /tmp/after with these commands:
$ touch -mt 08271145 /tmp/before
$ touch -mt 08271115 /tmp/after
$ find / -newer /tmp/before ! -newer /tmp/after -local -print
"Williams, David J" wrote:
--------------------------------------------------------
Larry A. Magnello larry.magnello_at_usa.net
Unix System Administrator TRU64 Unix System Administrator
DEC Unix, Solaris Unix, HP Unix, Linux Unix Sco Unix
Veritas Volume manager, DEC Logic Storage Manager
http://halite.westal.com/webstuff/fadein.html
<http://halite.westal.com/webstuff/fadein.html>
--------------------------------------------------------


****************************************************************************
***********************************


You want GNU find, from ftp://prep.ai.mit.edu/pub/gnu
<ftp://prep.ai.mit.edu/pub/gnu>
It has, eg. -mmin -amin, ...
Anthony A. D. Talltree [aad_at_lovecraft.talltree.net]


****************************************************************************
***********************************


Unfortunately, not really easy. But there are a couple ways I can know.
1. make a 0 size file for comparison
$ touch -t 12301700 timemarker # this file is dated Dec 30 17:00
$ find /var/adm/syslog.dated ! -newer timemarker # find older than Dec 30
17:00
2. use perl or even C code
$ perl -e ' # 1st argument is age in minutes, other arguments are filenames
$minutes = shift();
$seconds = $minutes*60;
$timenow = time();
while ($file = shift()) {
_at_s = stat($file);
# 10th element is ctime, 9th=mtime, 8th=atime
if ($s[10] < $timenow - $seconds) { # use > for younger than $minutes
print("deleting $file\n");
unlink($file);
}
}' 120 /var/adm/syslog.dated/*/*
-- 
Russ Berger 
Technical Account Manager (208)383-4807 
Business Critical Support Team Russell.Berger_at_digital.com 
Compaq Services 
****************************************************************************
***********************************
find /var/adm/syslog.dated  -depth -type d -exec
script_that_checks_and_rm.sh {}
\ ;
Nix.
Nikola Milutinovic [Nikola.Milutinovic_at_ev.co.yu]
****************************************************************************
***********************************
I *believe* GNU find has such feature, but I am not sure (I once installed
it on an Ultrix system which was lacking another find feature I had on Sun,
and now have on DU  ... I believe the man page mentioned also a granularity
finer than a day, but I never needed it).
----------------------------------------------------------------------------
Lucio Chiappetti - IFCTR/CNR - via Bassini 15 - I-20133 Milano (Italy)      
----------------------------------------------------------------------------
L'Italia ripudia la guerra [...] come    Italy repudiates war {...] as a
mezzo di risoluzione delle controversie  way of resolution of  international
internazionali                           controversies
		[Art. 11 Constitution of the Italian Republic]
----------------------------------------------------------------------------
For more info : http://www.ifctr.mi.cnr.it/~lucio/personal.html
<http://www.ifctr.mi.cnr.it/~lucio/personal.html>              
----------------------------------------------------------------------------
****************************************************************************
***********************************
Quick and dirty:
man find
*	newer file
	TRUE if the current file was modified more recently than the file
indi-cated by file.
	touch -t <suitable time> myfile
	find . -newer myfile or 
	find . ! -newer myfile 
	my 0.02euros
	-- 
	(O>  gu1d0 - guido_at_dsnet.it <mailto:guido_at_dsnet.it>  -
http://staff.dsnet.it/~guido <http://staff.dsnet.it/~guido>  //\  GB10958 -
Unix BOFH / Network Guy - PGP key available V_/_ "Unix _is_ user-friendly.
Just _very_ selective about his friends." We have more to fear from the
bungling of the incompetent than from the machinations of the wicked.
	
****************************************************************************
***********************************
	GNU find (part of GNU findutils in
ftp://prep.ai.mit.edu/gnu/findutils/ <ftp://prep.ai.mit.edu/gnu/findutils/>
) has some options to specify times in minutes:
	> find /var/adm/syslog.dated -depth -type d -ctime +5 -exec rm -rf
{} \ ;
	gnufind /foo -type f -cmin +120 -exec blah {} \;
	HTH (and happy new year !)
	-- 
	   _ ___
	 _| / __|      Andrea Paolini . Responsabile sistemi e networking
	/ . \__ \      DS Logics Srl . Via S.Felice 98 . Bologna . ITALY
	\___,___/ NET  Email: ap_at_dsnet.it <mailto:ap_at_dsnet.it>  . Phone:
+39-051-6583011
	
****************************************************************************
***********************************
	One way is to install the GNU findutils package
	(ftp://gatekeeper.dec.com/pub/GNU/findutils/
<ftp://gatekeeper.dec.com/pub/GNU/findutils/> ) which adds options for
smaller age units. Specifically, '-cmin 120' for your example.
	If you have installed Perl, you probably have a 'find2perl' command
that will output a Perl script that will also do the trick (after some easy
modifications). For example:
	find2perl /var/adm/syslog.dated -depth -type d -ctime +5 -exec rm
-rf {} \; > p1
	... then edit p1 to change '5' to (say) 0.08333
	Hope one of these ideas helps some.
	-- 
*	Paul A. Sand                 | perl -e 'print "Just \
*	University of New Hampshire  | another unimaginative \
*	pas_at_unh.edu <mailto:pas_at_unh.edu>                   | Perl
hacker.\n"'
*	http://pubpages.unh.edu/~pas <http://pubpages.unh.edu/~pas>  | 
****************************************************************************
***********************************
Try my awk script by fiddling with the time and deciding what you want to do
with the output.  I posted this to the group last year as a way of finding
out of time pop temp files and locks.
## This awk program checks for a lock file and removes it if its over 15
minutes old ## Run it with a cron every 10 mins.  It will look at the oldest
lock and whack ## it if over 15 mins. If < 15 mins or no locks it will exit
safely.
BEGIN {
while(1){
"date" | getline d
split (d,darray," ")
split (darray[4],t2,":")
tnow = darray[3]*1440  +t2[1]* 60 + t2[2]
## get date and parse it. create a value for minutes since day 1 of month
l="" "ls -lrt /data3/spool/mail | grep \.lock | grep -v clan" | getline l
print l ## edit above statement to reflect path to file or group of files u
r monitoring split (l,array," ") print array[9]
#
if (array[6] != darray[2]) 
		tnow = 1440
## handle special case of file creation and time now being in different
months split(array[8],larray,":") t=array[7]  *1440 +larray[1]*60 +
larray[2]
## create a value in mins since day 1 of month of file creation time
if(t==0) exit {if (tnow - t > 15) system("rm /data3/spool/mail/" array[9])
## whack it
		else
exit }
}
}
regards
stuart mckenzie
****************************************************************************
***********************************
If you have all the time in the world, you can use find to find all files
younger than a day, then in an -exec clause, feed ls -l through a sed or
grep filter and/or some time calculation to only display the ones matching
your time criterion.
But if you have lots of new files, it would probably be better to write a
program something like 'find' with finer granularity so you're not spawning
lots of 'ls' processes. 
-- 
J.James(Jim)Belonis II, U of Washington Physics Computer Cost Center Manager
belonis_at_phys.washington.edu <mailto:belonis_at_phys.washington.edu>  Internet
University of Washington Physics Dept. 
http://www.phys.washington.edu/~belonis
<http://www.phys.washington.edu/~belonis>  r. B234 Physics Astronomy
Building
1pm to midnite 7 days  (206) 685-8695   Box 351560      Seattle, WA
98195-1560
****************************************************************************
***********************************
Get GNU findutils at www.gnu.org <http://www.gnu.org> .
Naccarato, Robert [naccarar_at_bis.adp.com]
****************************************************************************
***********************************
You could touch a file to set it's modification time to the time threshold
you are interested in, then use -newer touched_file. Or you could get GNU
find, which permits smaller times to be specified.
Ian Goodacre
Computer and Telecommunication Services (CTS)
Management Board Secretariat
155 University Avenue, 8th floor
Toronto, Ontario, M5H 3B7
Tel: 416-327-1092
Fax: 416-327-3281
****************************************************************************
***********************************
I work this by using touch to create a file with the time stamp I am
interested in.  I then use find -older (actually, I usually am using find
-newer) to find the files.
Regards,
Mandell Degerness
Mandell.Degerness_at_gems2.gov.bc.ca <mailto:Mandell.Degerness_at_gems2.gov.bc.ca>
****************************************************************************
***********************************
I'm hoping you have received several replies. 
They should all say something like: 
Get the GNU version of find from any of the GNU/FSF mirror sites. 
It will allow finds at the hour level. 
Try: http://www.gnu.org/server/list-mirrors.es.html
<http://www.gnu.org/server/list-mirrors.es.html>  
*********************** 
Wayne Sweatt 
Principal Software Analyst 
Litton / PRC 
505.827.9288 
*********************** 
****************************************************************************
***********************************
David J Williams
Technical Specialist
Information Services
F H Faulding & Co Limited
Tel: +61 8 8408 3450/ Fax: +61 8 8408 3500
mailto:david.j.williams_at_au.faulding.com
<mailto:david.j.williams_at_au.faulding.com> 
http:www.faulding.com
Received on Tue Jan 04 2000 - 01:00:17 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:40 NZDT