![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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! |
|
||||
|
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? |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|