Operating System - HP-UX
1833105 Members
3186 Online
110051 Solutions
New Discussion

Re: Removing files dated in the future.

 
SOLVED
Go to solution
John Jayaseelan
Super Advisor

Removing files dated in the future.

Hi
Hope someone can help me here, I'd be very grateful!

We have some files, quite a lot I'd guess, that have a date & time stamp in the future. This is because the Unix date has been changed back & forth on the box for User Acceptance Testing. These files are now causing a problem & I've been asked to remove everything that is time stamped with a future date.
Can someone possibly give me an idea how best to go about it, we know the directories they will be in & I'm guessing that find, grep or awk may do the trick. however I'm not too sure of the right syntax.

Many thanks in anticipation
Sue
5 REPLIES 5
Darrell Allen
Honored Contributor
Solution

Re: Removing files dated in the future.

Hi Sue,

Use find with the -newer option.

Touch a reference file, perhaps /tmp/reference. It will be created with the current date/time.
find /dir -newer /tmp/reference -exec rm {} \;

I'd use -exec ll -d {} \;
before I actually ran with the rm just to be safe.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Trond Haugen
Honored Contributor

Re: Removing files dated in the future.

Create a reference file with touch with a sutable date and use find with the -newer option to find them.

#touch -t 03011212 XX #Just creating an example file to find later
#touch -t 02281212 ref
#find . -newer ref
./XX

Of course you could remove them with the find command:
#find . -newer ref -exec rm {} \;

Hope this helps,
Trond
Regards,
Trond Haugen
LinkedIn
Peter Kloetgen
Esteemed Contributor

Re: Removing files dated in the future.

Hi Sue,

you could use the find- command with -newer to solve your problem:

find /path_to_directory -newer /path_to_time_reference_file -exec rm {}\;

if the number of files is not to big or if you want to make sure not to delete wrong files, you could also use -ok instead of -exec. This would mean you have to answer a confirming question with "y" to remove the file.


Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
John Jayaseelan
Super Advisor

Re: Removing files dated in the future.

Wow Rapid response !! Thanks Guys ;-))

I'm actually away from my system today, & am just preparing for tomorrow, so I'll give your suggestions a try then & assign points after.

Many thanks once again
Sue
John Jayaseelan
Super Advisor

Re: Removing files dated in the future.

Hi all who helped me out.

The job got pulled in the end, so I didn't have to do it. However I tried out your suggestions on a test box & they all worked perfectly. Great reference for later.
Points assigned
Thanks for all youe assistance.

Sue