Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-03-2002
Registered User
 
Join Date: Sep 2002
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 12-03-2002
criglerj's Avatar
Registered User
 
Join Date: May 2002
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 12-04-2002
hassan2 hassan2 is offline Forum Advisor  
Registered User
 
Join Date: Mar 2002
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 12-09-2002
criglerj's Avatar
Registered User
 
Join Date: May 2002
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:41 AM.