The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find files older than 2 hours pt14 AIX 3 03-05-2008 12:31 PM
Delete logs every 3 hours tungaw2004 UNIX for Dummies Questions & Answers 3 12-09-2007 08:22 AM
Files created in last 24 hours jayaramanit Shell Programming and Scripting 1 09-08-2007 04:34 AM
move log files over 12 hours old... Thomas Pluck Shell Programming and Scripting 1 07-06-2004 04:37 AM
Finding files older than 2 hours ianf Shell Programming and Scripting 1 05-27-2002 10:51 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2002
hedrict hedrict is offline
Registered User
  
 

Join Date: Jun 2001
Posts: 35
delete files that are over 2 hours old

guys,

I have a need for a script that will delete all files in a given directory that are over 2 hours old. I will set this up to run in cron. I'm having a little trouble coming up with the syntax that will identify these files. Is there a variation of the ls command that I can use to identify these files? Any help will be appreciated.

Thanks!
  #2 (permalink)  
Old 06-30-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Use the "date" command to get the current date and time. Then subtract 2 from the hours. This may require adjusting the date if you are close to midnight. Once you have the date and time of 2 hours ago, use the "touch" command to create a temp file with that mtime. Next, use the "find" command is get a list of files older than the temp file and delete them. Finally, remove that temp file.
  #3 (permalink)  
Old 06-30-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
mmm tough one... I know how to do this for files that were modified 'n' number of days ago...but I'm not sure about hours....

find . -mtime +5 -exec rm {} \;

This will remove files over 5 days old..... but the sytax for mtime states days only.... i tried decimals..but no joy.... anyone know if mtime or an equivalent can be used for hours?
  #4 (permalink)  
Old 07-01-2002
flounder flounder is offline
Registered User
  
 

Join Date: Jun 2002
Location: PA
Posts: 17
I know the date command when formatted with give you the time.

Example:

phdb102 [ogd] >date +%H:%M
12:02

This is the using variables in a shell script:

#!/usr/bin/ksh

the_hour=`date +"%H"`
the_min=`date +"%M"`
calc_time=`expr $the_hour - 2`
echo "The current time is $the_hour:$the_min"
echo "This is the calculated time $calc_time:$the_min"

The result:

phdb102 [ogd] >the_time.sh
The current time is 12:04
This is the calculated time 10:04

Knowing this I am not sure how to incorporate this into the find command. I will experiment and let you know what I come up with.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0