How to delete files which are 7 days old | Unix Linux Forums | UNIX for Dummies Questions & Answers

  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 !!

How to delete files which are 7 days old

UNIX for Dummies Questions & Answers


Tags
mtime

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-10-2001
arunava_maity arunava_maity is offline
Registered User
 
Join Date: Apr 2001
Last Activity: 30 May 2001, 2:21 AM EDT
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Hi all,
how to write a script that will indentify the files in a directory which are 7 days old and delete those files.
Thanks in advance
Cheers
Arunava
Sponsored Links
    #2  
Old 04-10-2001
98_1LE 98_1LE is offline Forum Advisor  
Registered User
 
Join Date: Dec 2000
Last Activity: 21 May 2012, 6:37 PM EDT
Location: Greater Dallas area
Posts: 405
Thanks: 0
Thanked 3 Times in 3 Posts
one liner

find /path/to/dir -ctime +7 -exec rm -f {} \;
Sponsored Links
    #3  
Old 04-19-2001
kikkin
Guest
 
Posts: n/a
Can u explain this command. please!
    #4  
Old 04-19-2001
kornshellmaven kornshellmaven is offline
Registered User
 
Join Date: Apr 2001
Last Activity: 10 August 2009, 3:53 PM EDT
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
I use a slight variation on
find /path/to/dir -ctime +7 -exec rm -f {} \;


find /path/to/dir -mtime +7 -type f -exec rm -f {} \;

I recommend the "-type f" because this restricts to regular files.

One of my coworkers had coded -rf on the rm statement with out the -type f & ended up deleting directories.

We use this code to purge files from an application archive directory (logs, data, etc.)


ps - Do a "man find" to find out what the command does.
Sponsored Links
    #5  
Old 04-30-2001
arunava_maity arunava_maity is offline
Registered User
 
Join Date: Apr 2001
Last Activity: 30 May 2001, 2:21 AM EDT
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Computer

Hi Maven,
Thanks for the solution.but recently i am having a problem with deleting the files.if i go to the backup directory and just give the ls command to how many files are there and then run this command its not working .on the other hand if i don't go to the directory and run this command its working perfectly.
Urgently require help
cheers
Thanks in advance
Arunava
Sponsored Links
    #6  
Old 04-30-2001
kornshellmaven kornshellmaven is offline
Registered User
 
Join Date: Apr 2001
Last Activity: 10 August 2009, 3:53 PM EDT
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
BEFORE I issue an "rm" command inside a find -exec, I always test it extensively to be sure it's working properly.

There are a few variations:

find /path/to/dir -mtime +7 -type f -exec ls -l {} \;
This will give a long listing of the files which satisfy the find criteria. i.e. the ones to be deleted.

You can also try:

find /path/to/dir -mtime +7 -type f -print

If you use "." in place of /path/to/dir - ALL directories below your starting point will be searched.

Typical:
cd /dir/to/purge
find . -mtime +7 -type f -exec ls -l {} \;

Good luck
Sponsored Links
    #7  
Old 05-09-2001
n9ninchd n9ninchd is offline
Registered User
 
Join Date: May 2001
Last Activity: 20 December 2001, 8:34 PM EST
Location: Bay Area
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
What if you wanted to remove only files from today
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
How do i delete files older than 15 days in AIX? bluesteel AIX 4 03-31-2010 11:23 AM
Delete files older than 30 days tlphillips UNIX for Dummies Questions & Answers 3 07-24-2008 05:11 PM
How to delete files over 30 days GEBRAUN UNIX for Dummies Questions & Answers 2 01-25-2006 12:58 AM
delete files older than 7 days lesstjm UNIX for Dummies Questions & Answers 1 11-06-2001 09:43 AM



All times are GMT -4. The time now is 12:00 PM.