Delete files older than 7 days?

General support questions including new installations

Delete files older than 7 days?

Postby gertrudis » 2010/01/26 02:42:56

Hi to all.
I've been trying to delete all files older than 7 days in a directory temp1.
I have try different ways but nothing happend:

find /temp1/* -mtime +7 -exec rm rf\
find . -mtime +7 -exec rm rf\
find /temp1/* -mtime +7 -print -exec rm{} \

can somebody pointme to the wright direction?

thanks in advance
gertrudis
 
Posts: 6
Joined: 2010/01/26 02:13:07

Re: Delete files older than 7 days?

Postby cry4dawn » 2010/01/26 02:47:54

find /temp1/* -mtime 7 -print -exec rm -f {} \;
cry4dawn
 
Posts: 108
Joined: 2009/09/23 01:48:56

Re: Delete files older than 7 days?

Postby gertrudis » 2010/01/26 03:30:59

I try it and i looks like its working, but still files are in the folder

find /temp1/ -mtime 7 -print -exec rm -f {} \;
gertrudis
 
Posts: 6
Joined: 2010/01/26 02:13:07

Re: Delete files older than 7 days?

Postby cry4dawn » 2010/01/26 05:04:39

use the asteric or:
find /temp1/ -mtime 7 -type f -print -exec rm -f {} \;
cry4dawn
 
Posts: 108
Joined: 2009/09/23 01:48:56

Re: Delete files older than 7 days?

Postby gertrudis » 2010/01/26 15:10:18

Doesn't work, I have try and try two with minutes and still the same problems, it does all proccess but no file are deleted.

I try it this:
find /temp1/ -mtime 7 -type f -print -exec rm -f {} \;

and with minutes too:
find /temp1/ -mmin 7 -type f -print -exec rm -f {} \;
gertrudis
 
Posts: 6
Joined: 2010/01/26 02:13:07

Re: Delete files older than 7 days?

Postby toracat » 2010/01/26 15:37:50

The command provided by cry4dawn should work fine.

Do you have the correct permission bits set for the files to be deleted and the directory they are in? Is there any chance that the filesystem is read-only? When you run the command, do you see any error message?
User avatar
toracat
Forum Moderator
 
Posts: 6981
Joined: 2006/09/03 16:37:24
Location: California, US

Re: Delete files older than 7 days?

Postby AlanBartlett » 2010/01/26 18:51:47

Two points. The find manual page suggests that the braces may need to be escaped in certain circumstances and the -print isn't necessary.

Hence I would use --

Code: Select all
[b]find /temp1 -mtime 7 -type f -exec rm -f \{\} \;[/b]
User avatar
AlanBartlett
Forum Moderator
 
Posts: 9165
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk

Re: Delete files older than 7 days?

Postby pschaff » 2010/01/26 22:14:36

If you want older than 7 days, add "+"
Code: Select all
find /temp1 -mtime +7 -type f -exec rm -f {} \;


For 7 days or older
Code: Select all
find /temp1 -mtime +6 -type f -exec rm -f {} \;


And I'd test first with "rm -i". :-)
pschaff
Retired Moderator
 
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America

Delete files older than 7 days?

Postby michaelnel » 2010/01/26 22:18:50

I'd test it first without any rm at all, just to see the list of files and inspect their age. On any "mass rm" kinda thing, I like to build up the line slowly to make sure it's finding what I want to operate on and nothing more.
michaelnel
 
Posts: 1479
Joined: 2006/05/29 16:50:11
Location: San Francisco, CA

Re: Delete files older than 7 days?

Postby pschaff » 2010/01/26 22:26:46

Good point:
Code: Select all
find /temp1 -mtime +7 -type f -ls
OR
find /temp1 -mtime +7 -type f -exec ls -l {} \;
pschaff
Retired Moderator
 
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America

Next

Return to CentOS 5 - General Support

Who is online

Users browsing this forum: No registered users and 0 guests