General
Showing results for 
Search instead for 
Do you mean 

Delete files older than 1 hour

SOLVED
Go to Solution
Occasional Visitor

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
Trusted Contributor 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.
Occasional Visitor

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
Outstanding Contributor Outstanding Contributor

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
Occasional Visitor

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
Occasional Visitor

Re: Delete files older than 1 hour

Pete,

Thanks a lot. It works.

Thanks,
Sergiy
Occasional Visitor

Re: Delete files older than 1 hour

Answer of Pete