If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script need to delete files by "file type and time"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-07, 14:27
joy32327 joy32327 is offline
Registered User
 
Join Date: Mar 2007
Location: Tallahassee, FL
Posts: 10
script need to delete files by "file type and time"

I wanted to edit an existing shell script that I have that will delete only the *.log files older than 7 days. My existing script will delete all files older than 7 days. It is as follows:

# Oracle Archive Log Clean-up Process
#
PATH=.:/usr/local/bin:$PATH
ORACLE_SID=$1
ORAENV_ASK=NO
export PATH ORACLE_SID ORAENV_ASK
. /usr/local/bin/oraenv
#
echo "Starting Oracle Archive Log Clean-up Process"
cd /u01/app/oracle/product/ora10g/dbs
echo "Files being deleted ..."
find . -mtime +7 print
find . -mtime +7 -exec rm {} \;
echo "done ... Oracle Archive Log Clean-up Process"

Why? I have other files other than *.log files in this directory. Running the script would delete files that I need because it doesn't discrimate against the file type.
Reply With Quote
  #2 (permalink)  
Old 04-17-07, 16:23
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Hi,

How do you expect 'find' to discriminate in filetypes? To accomplish that and to exclude directories with the same extension use:
Code:
find . -name "*.log" -type f -mtime +7 -exec rm {} \;
Regards
Reply With Quote
  #3 (permalink)  
Old 04-17-07, 17:02
joy32327 joy32327 is offline
Registered User
 
Join Date: Mar 2007
Location: Tallahassee, FL
Posts: 10
Thank you very much for your reply. This is exactly what I needed.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On