Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2007
    Location
    Tallahassee, FL
    Posts
    10

    Unanswered: 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.

  2. #2
    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

  3. #3
    Join Date
    Mar 2007
    Location
    Tallahassee, FL
    Posts
    10
    Thank you very much for your reply. This is exactly what I needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •