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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove logs by date cvdev SUN Solaris 3 05-31-2008 03:09 AM
Sorting Files by date and moving files in date order rebel64 Shell Programming and Scripting 2 03-11-2008 12:45 PM
Remove the date from the file pradkumar UNIX for Dummies Questions & Answers 5 01-10-2008 01:36 AM
Remove out date logs eric_wong_ch Shell Programming and Scripting 2 10-09-2007 11:52 AM
Remove files based on date hshapiro UNIX for Dummies Questions & Answers 4 12-09-2005 12:21 PM

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

Join Date: Jun 2006
Posts: 1
how to remove files with a date

I have files with a date name ( 20060506 20060507 etc..) that i want to remove
because it keeps filling up the directory. Can someone please help me with a script to remove those date files. i would like to keep atleast 14 days worth from the current date. I hope i have explained it clearly and thanks
  #2 (permalink)  
Old 06-12-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
search forums

Use Perderabo's datecalc and see this post and you will get some idea on how to proceed.
  #3 (permalink)  
Old 06-12-2006
Mike_the_Man Mike_the_Man is offline
Registered User
  
 

Join Date: May 2006
Location: MD
Posts: 16
Quote:
Originally Posted by justintime
I have files with a date name ( 20060506 20060507 etc..) that i want to remove
because it keeps filling up the directory. Can someone please help me with a script to remove those date files. i would like to keep atleast 14 days worth from the current date. I hope i have explained it clearly and thanks

Can you do it based upon modification time instead of filename?

The below will remove all files in <dir> that have not been modified in the past 14 days.
Code:
find <dir> -mtime +14 -exec rm -f {} \;
  #4 (permalink)  
Old 09-08-2006
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
Quote:
Originally Posted by Mike_the_Man
Can you do it based upon modification time instead of filename?

The below will remove all files in <dir> that have not been modified in the past 14 days.
Code:
find <dir> -mtime +14 -exec rm -f {} \;
will the below script of mine work this way?

#! /bin/sh

Today_Date=`date +%Y%m%d`
log=`/usr/TRS/HULFT/movedata.log`

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} > ${log}

find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -fr {} \; > ${log}
  #5 (permalink)  
Old 09-08-2006
Mike_the_Man Mike_the_Man is offline
Registered User
  
 

Join Date: May 2006
Location: MD
Posts: 16
Quote:
Originally Posted by lweegp
will the below script of mine work this way?

#! /bin/sh

Today_Date=`date +%Y%m%d`
log=`/usr/TRS/HULFT/movedata.log`

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} > ${log}

find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -fr {} \; > ${log}
The setting of the log variable line will give you an error using the `.
The rest looks ok. I would change would be the redirects on your log files. If you want a new log file everyday, then you can rm the logfile at the beginning of your script. The find command will work. I changed the search path a little, but your version should work as well. Your script will probably leave a bunch of directories, /usr/TRS/backup/<date>, out there. I would include something to clean that up. See below for the changes.
I hope this helps.

Mike


Code:
#! /bin/sh

Today_Date=`date +%Y%m%d`
log="/usr/TRS/HULFT/movedata.log"

#If you want a new log file on each run
rm -f ${log}

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} >> ${log} 2>> ${log}

find /usr/TRS/backup -name 'T*' -mtime +1 -exec rm -fr {} \; >> ${log} 2>> ${log}
  #6 (permalink)  
Old 09-10-2006
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
Quote:
Originally Posted by Mike_the_Man
The setting of the log variable line will give you an error using the `.
The rest looks ok. I would change would be the redirects on your log files. If you want a new log file everyday, then you can rm the logfile at the beginning of your script. The find command will work. I changed the search path a little, but your version should work as well. Your script will probably leave a bunch of directories, /usr/TRS/backup/<date>, out there. I would include something to clean that up. See below for the changes.
I hope this helps.

Mike


Code:
#! /bin/sh

Today_Date=`date +%Y%m%d`
log="/usr/TRS/HULFT/movedata.log"

#If you want a new log file on each run
rm -f ${log}

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} >> ${log} 2>> ${log}

find /usr/TRS/backup -name 'T*' -mtime +1 -exec rm -fr {} \; >> ${log} 2>> ${log}
Hi Mike,

Thanks for the help. I think this shld work well. Many Thanks again =)

regards
wee
Closed Thread

Bookmarks

Tags
mtime

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 06:50 AM.


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