Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Deleting files older than a given date

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-03-2002
rajugp1 rajugp1 is offline
Registered User
 
Join Date: Sep 2002
Last Activity: 27 January 2003, 7:37 AM EST
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Deleting files older than a given date

Hi all,

I want to delete all files in a directory which are older than a given date.

I thought of doing it by creating a file by the required date by using touch command. And then i would use find command on that file and try to find files older than that.

I searched the man and found a newer option for find command.
But i didn't get the opposite of it (i would like to find older files)

Can anyone please tell me the easiest way to do that?

Thanks in advance,
raju
Sponsored Links
    #2  
Old Unix and Linux 12-03-2002
criglerj's Unix or Linux Image
criglerj criglerj is offline
Registered User
 
Join Date: May 2002
Last Activity: 7 September 2008, 10:24 PM EDT
Location: Atlanta
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
Read your "find" man page carefully and see if "-mtime +3" is the opposite of "-mtime -3". It is in some newer versions of find, and you may have one.

This is a case where posting the result of "uname -sr" or something similar would allow those with specialized knowledge to help more.
Sponsored Links
    #3  
Old Unix and Linux 12-04-2002
hassan2 hassan2 is offline Forum Advisor  
Registered User
 
Join Date: Mar 2002
Last Activity: 6 January 2005, 4:33 PM EST
Location: London, England
Posts: 262
Thanks: 0
Thanked 2 Times in 2 Posts
you could use the find command

eg

find /my_current_directory -mtime +5 -exec rm {} \;


Note
To find files created more than 5 days use -mtime +5
To find files created less than 5 days use -mtime -5
    #4  
Old Unix and Linux 12-09-2002
criglerj's Unix or Linux Image
criglerj criglerj is offline
Registered User
 
Join Date: May 2002
Last Activity: 7 September 2008, 10:24 PM EDT
Location: Atlanta
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally posted by hassan2
you could use the find command


Code:
find /my_current_directory -mtime +5 -exec rm {} \;

If there are a lot of these files, you'll save time with

Code:
find /my_current_directory -mtime +5 -print | xargs rm

I.e., invoke "rm" on large groups of files --- frequently only once.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting files older than 6 hours subhasri_2020 Shell Programming and Scripting 13 01-31-2011 02:16 PM
deleting files older than 7 days MAYAMAYA0451 Shell Programming and Scripting 1 01-02-2011 11:49 PM
Deleting older files of a particular type cmap UNIX for Advanced & Expert Users 6 09-30-2009 04:09 AM
Deleting files older than 7 days shezam Shell Programming and Scripting 4 07-09-2008 04:40 AM
Deleting Files Older than 24 hours mazhar803 Solaris 7 09-27-2007 07:30 AM



All times are GMT -4. The time now is 06:36 AM.