Delete files older than 1 hour (511 Views)
Reply
Occasional Visitor
kiberpress
Posts: 5
Registered: ‎05-22-2007
Message 1 of 7 (511 Views)
Accepted Solution

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
Trusted Contributor
Danny Petterson - DK
Posts: 249
Registered: ‎02-09-2007
Message 2 of 7 (511 Views)

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
kiberpress
Posts: 5
Registered: ‎05-22-2007
Message 3 of 7 (511 Views)

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
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 4 of 7 (511 Views)

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
kiberpress
Posts: 5
Registered: ‎05-22-2007
Message 5 of 7 (511 Views)

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
kiberpress
Posts: 5
Registered: ‎05-22-2007
Message 6 of 7 (511 Views)

Re: Delete files older than 1 hour

Pete,

Thanks a lot. It works.

Thanks,
Sergiy
Occasional Visitor
kiberpress
Posts: 5
Registered: ‎05-22-2007
Message 7 of 7 (511 Views)

Re: Delete files older than 1 hour

Answer of Pete
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.