Find the answer to your Linux question:
Results 1 to 4 of 4
Hi guys I got this part from my script working that it will delete a folder is from 8 days ago EightDaysAgo=`(date --date="8 days ago" +%d-%m-%Y)` rm -rf $EightDaysAgoTar However ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    19

    What to write synatax to delete stuff older than 8 days

    Hi guys I got this part from my script working that it will delete a folder is from 8 days ago

    EightDaysAgo=`(date --date="8 days ago" +%d-%m-%Y)`

    rm -rf $EightDaysAgoTar

    However I need to remove files that are older than 8days for example if the script is'nt run for a day it will remove both the 9th and 8th day one not just the 8th day one. If I'm making any sense lol

    Thanks in advanced

  2. #2
    Linux Newbie Nagarjuna's Avatar
    Join Date
    Feb 2011
    Posts
    122
    You could try the below:

    Code:
    find /location/of/files -type f -mtime +8 | xargs rm
    The above should find all files 8 days or older in desired directory and delete them. Does this achieve what your looking to do?

  3. #3
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,097
    +1 Nagarjuna
    but maybe it makes sense to include -name to not accidentally delete the wrong files.
    Match the name as closely as possible.

    Code:
    find /location/of/files -type f -name "*.tar" -mtime +8 -delete
    You must always face the curtain with a bow.

  4. #4
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    For the sake of your own sanity, please check the consequences of any destructive command before committing to it.

    Code:
    find /location/of/files -type f -name "*.tar" -mtime +8 -print

Posting Permissions

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