Operating System - HP-UX
1748171 Members
4181 Online
108758 Solutions
New Discussion юеВ

Re: Delete files older than 1 hour

 
SOLVED
Go to solution
kiberpress
New Member

Delete files older than 1 hour

Hi,

I found a lot of suggestions about delete files older than XX days.
But I didn't find how to delete files older than 1 hour.
It's a pity but find command with mtime parameter work with multiple of days.
Could you help me with this issue?

Thanks,
Sergiy
6 REPLIES 6
Danny Petterson - DK
Trusted Contributor

Re: Delete files older than 1 hour

You proberbly have to make a script, which makes a filelist of the directory where the files are, and then awks on the columns with date and time, compares it to sysdate/time and finally, removes it it its more than one hour old.

A bit complicated, but that should do the trick.
kiberpress
New Member

Re: Delete files older than 1 hour

Danny,

I agree - this is solution.
I am looking for some standard ways like find :)

Thanks anyway,
Sergiy
Pete Randall
Outstanding Contributor
Solution

Re: Delete files older than 1 hour

Use touch to create a reference file with a time stamp one hour ago, then use find with the "! -newer ref_file" switch :

find /start_dir -type f ! -newer ref_file |xargs rm


Pete

Pete
kiberpress
New Member

Re: Delete files older than 1 hour

Pete,

Wow! What's a great solution :)
I'll try it and come back soon with results.

Thanks,
Sergiy
kiberpress
New Member

Re: Delete files older than 1 hour

Pete,

Thanks a lot. It works.

Thanks,
Sergiy
kiberpress
New Member

Re: Delete files older than 1 hour

Answer of Pete