Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

Delete files older than 1 hour

SOLVED
Go to solution
kiberpress
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
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
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
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
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
kiberpress
Occasional Visitor

Re: Delete files older than 1 hour

Pete,

Thanks a lot. It works.

Thanks,
Sergiy
kiberpress
Occasional Visitor

Re: Delete files older than 1 hour

Answer of Pete