Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Deleting files created before two days ago

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-13-2002
josecollantes josecollantes is offline
Registered User
 
Join Date: Aug 2001
Last Activity: 21 February 2002, 11:05 AM EST
Location: Peru
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Data Deleting files created before two days ago

Dear All:

I want to build a shell that delete files created two or more days ago ... I think it could be built using a special command with ls or grep, I'd apreciate any help from you guys

I have a lot of log files from november, december, january and this tool will help me a lot

The files are in different directories, but all of them under my $HOME directory

Cheers

Jose
Sponsored Links
    #2  
Old Unix and Linux 02-13-2002
knarayan knarayan is offline
Registered User
 
Join Date: Jan 2002
Last Activity: 29 July 2002, 4:47 PM EDT
Location: NJ
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
You could use the find command to look for files modified or accessed 2 days ago and remove them. You can do a man find to get more details. Here is an ex:
syntax:
find <directory_name> -name <filename> -mtime +2 -exec rm {} \;

find /ora_export -name "exp*" -mtime +2 -exec rm {} \;

The above command looks for filenames starting with exp which were created/modified 2 days ago and removes them.
You could put it in a shell program also.
mtime means modified time
atime means access time
you could use the one applicable to you.

Hope this helps.
Sponsored Links
    #3  
Old Unix and Linux 02-13-2002
Jimbo
Guest
 
Posts: n/a
Following command will find and list files older than 2 days from right now, not on clean calendar day divisions, and of course it also searches subdirectories:

find mydir -type f -mtime +2 -exec ls -ld {} \;

To remove them, change the ls -ld to rm -f

(Sorry knarayan, you covered it well, but your reply was not there when I started my reply)
    #4  
Old Unix and Linux 02-21-2002
josecollantes josecollantes is offline
Registered User
 
Join Date: Aug 2001
Last Activity: 21 February 2002, 11:05 AM EST
Location: Peru
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very much

Thank you very much guys, I implemented this procedure and works very fine !!!

Sorry for not send my response before, my company replaced our web server ....

Thanks a lot

Jose
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find the sum of files created 5 days before bang_dba Shell Programming and Scripting 4 02-02-2012 06:10 AM
How to find files created some days before? jyotidas UNIX for Dummies Questions & Answers 6 07-27-2010 07:27 AM
Remove files which created date before 10 days on HP-UX murad_fayez Shell Programming and Scripting 1 12-21-2008 05:05 AM
List files created before Noon 2 days prior prismtx Shell Programming and Scripting 3 01-19-2008 11:06 AM
Deleting certain files over 30 days old swellybro UNIX for Dummies Questions & Answers 3 09-26-2006 11:25 AM



All times are GMT -4. The time now is 02:16 PM.