Results 1 to 4 of 4

Thread: Remove files older than 3 months except directories

  1. #1
    Join Date
    Jan 2009
    Posts
    134

    Remove files older than 3 months except directories

    Hello friends

    I'm in search for a shell script which can removes all files which is older than 3 months from present day.but i need to preserve my directory files,My log files saved in the date format
    TIMESTAMP=`date +%Y%m%d%H%M%S`
    LOG=/log/log_${TIMESTAMP}.log

    any thoughts?

  2. #2
    Join Date
    May 2008
    Posts
    2,680

    Re: Remove files older than 3 months except directories

    i think this Code will work for you:

    find /path/to/files -mtime +30 -exec rm {}\;

    Modify the /path/to/files as you need, obviously -mtime +30 means modify the date as your wish and delete it

    enjoy....

  3. #3
    Join Date
    Jan 2009
    Posts
    1,738

    Re: Remove files older than 3 months except directories

    Find utility on linux, use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.

    find /path/to/files* -mtime +5 -exec rm {} \;
    the first argument is the path to the files. This can be a path, a directory, or a wildcard. The second argument, -mtime, is used to specify the number of days old that the file is finally -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

  4. #4
    Join Date
    Jan 2008
    Posts
    3,388

    Re: Remove files older than 3 months except directories

    this can use to delete all files over 60 days
    find . -atime +60 -type f -exec rm -f {} \;

    find . -atime +60 -exec rm -rf {} \;

    good luck..btu i think it will delete your directory also

Similar Threads

  1. Remove unnecessary months/Quarters
    By niravrph in forum Microsoft Project
    Replies: 19
    Last Post: 19-04-2011, 03:58 PM
  2. Replies: 4
    Last Post: 09-02-2010, 05:40 PM
  3. Distinguishing between files and directories
    By Flacos in forum Software Development
    Replies: 3
    Last Post: 05-12-2009, 04:13 PM
  4. List all Files and Directories in a Directory
    By Samir_1 in forum Software Development
    Replies: 0
    Last Post: 08-12-2008, 07:32 PM
  5. How to Secure NTFS files and directories
    By T.J. in forum Tips & Tweaks
    Replies: 0
    Last Post: 11-11-2008, 02:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,503,506.73663 seconds with 16 queries