Results 1 to 4 of 4

Thread: Unix / Linux: Find and delete file older than 45 days automatically

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Unix / Linux: Find and delete file older than 45 days automatically

    i can delet the file i want using

    Code:
    find /var/spool/asterisk/monitor/ -iname '*.wav' -ctime +45 -exec rm -f {} \;
    but this delete all wav file i want it deletes just wav files older than 45days automatically

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,515
    Thanks
    17
    Thanked 815 Times in 511 Posts
    Rep Power
    10

    Default

    Code:
    #!/bin/bash
    ago=$(date +%Y-%m-%d '--date=45 days ago')
    file="/tmp/file.$$"
    touch --date $ago "$file"
    find /path/to/dest/ -type f -newer "$file"
    ### To delete use following syntax ###
    ### find /path/to/dest/ -type f -newer "$file" -delete ###
    ### find /var/spool/asterisk/monitor/ -type f -iname "*.wav" -newer "$file" -delete
    
    rm -f "$file"
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    is following enough ? (to delete wav files older than 45days in /var/spool/asterisk/monitor/)



    Code:
    #!/bin/bash
    ago=$(date +%Y-%m-%d '--date=45 days ago')
    file="/tmp/file.$$"
    touch --date $ago "$file"
    find /path/to/dest/ -type f -newer "$file"
    find /var/spool/asterisk/monitor/ -type f -iname "*.wav" -newer "$file" -delete
    
    rm -f "$file"
    Last edited by zodehala; 5th February 2012 at 01:56 AM.

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Use find and delete action

    Quote Originally Posted by zodehala View Post
    i can delet the file i want using

    Code:
    find /var/spool/asterisk/monitor/ -iname '*.wav' -ctime +45 -exec rm -f {} \;
    but this delete all wav file i want it deletes just wav files older than 45days automatically
    It depends what older means, I assume it means modified.

    Here it is:
    Code:
    find . -type f -mtime +45 -delete
    This will delete files modified more than 45 days.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Shell script to find remaing days (subtract two dates)
    By jmishal in forum Shell scripting
    Replies: 3
    Last Post: 7th March 2013, 07:53 AM
  2. Shell script to kill process Automatically after 3 days
    By darknet in forum Shell scripting
    Replies: 4
    Last Post: 2nd November 2009, 01:40 AM
  3. Replies: 0
    Last Post: 5th February 2009, 01:59 AM
  4. Find Unix Linux File / Directory by date And Then Copy / Move File
    By asim.mcp in forum CentOS / RHEL / Fedora
    Replies: 1
    Last Post: 10th August 2008, 04:30 AM
  5. Shell Script to Automatically Delete a File via Cron Job
    By kakarla in forum Shell scripting
    Replies: 2
    Last Post: 29th January 2008, 09:54 AM

Posting Permissions

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