Operating System - HP-UX
1833863 Members
2013 Online
110063 Solutions
New Discussion

how to find files created within last few hours ?

 
SOLVED
Go to solution
Sammy_2
Super Advisor

how to find files created within last few hours ?

I can use find command with ctime, mtime to find files within days ? How do I find files that were created in the last two hours ? Or lets say, files created since 7:30Am today ?
good judgement comes from experience and experience comes from bad judgement.
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: how to find files created within last few hours ?

Use the touch command to create a reference file 2 hours older, then use find with the -newer option.


Pete

Pete
Hai Nguyen_1
Honored Contributor

Re: how to find files created within last few hours ?

Sam,

You can use "touch" to create a file with a desired creation time. Then you use it with find (I am not near an HP box to give you a correct syntax) to find files created since then.

Hai
Umapathy S
Honored Contributor
Solution

Re: how to find files created within last few hours ?

Sam,
You can use a temp file which is created with the reference time like

$touch -t 06120730 /tmp/tmp.out

and then

$find -type f -newer tmp.out

HTH
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Armin Feller
Honored Contributor

Re: how to find files created within last few hours ?

Or us the following options (-nt or -ot)in korn shell to find out if a file is newer/older as a referece file.

Check with following small script:

#!/bin/ksh ($1, $2 are filename parameters to this script)
if [ $1 -nt $2 ]
then
echo File $1 is newer than file $2
else
echo File $1 is older than file $2
endif

Regards...
Armin
Sammy_2
Super Advisor

Re: how to find files created within last few hours ?

Thanks Pete and Hai.
I used touch -t command then then newer command in the find command to find the files. It worked.
good judgement comes from experience and experience comes from bad judgement.
Sammy_2
Super Advisor

Re: how to find files created within last few hours ?

Uma solution was exactly what I did and it worked for me although others were on the same track but could not recall the exact syntax. Thanks Armin but I am looking for quick 1 or 2 lines command.
good judgement comes from experience and experience comes from bad judgement.