Delete files older than 7 days?

General support questions including new installations
gertrudis
Posts: 6
Joined: 2010/01/26 02:13:07
Contact:

Delete files older than 7 days?

Post by 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

cry4dawn
Posts: 108
Joined: 2009/09/23 01:48:56

Re: Delete files older than 7 days?

Post by cry4dawn » 2010/01/26 02:47:54

find /temp1/* -mtime 7 -print -exec rm -f {} \;

gertrudis
Posts: 6
Joined: 2010/01/26 02:13:07
Contact:

Re: Delete files older than 7 days?

Post by 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 {} \;

cry4dawn
Posts: 108
Joined: 2009/09/23 01:48:56

Re: Delete files older than 7 days?

Post by cry4dawn » 2010/01/26 05:04:39

use the asteric or:
find /temp1/ -mtime 7 -type f -print -exec rm -f {} \;

gertrudis
Posts: 6
Joined: 2010/01/26 02:13:07
Contact:

Re: Delete files older than 7 days?

Post by 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 {} \;

User avatar
toracat
Site Admin
Posts: 7518
Joined: 2006/09/03 16:37:24
Location: California, US
Contact:

Re: Delete files older than 7 days?

Post by toracat » 2010/01/26 15:37:50

The command provided by [b]cry4dawn[/b] 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
AlanBartlett
Forum Moderator
Posts: 9345
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: Delete files older than 7 days?

Post by AlanBartlett » 2010/01/26 18:51:47

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

Hence I would use --

[code]
[b]find /temp1 -mtime 7 -type f -exec rm -f \{\} \;[/b]
[/code]

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Delete files older than 7 days?

Post by pschaff » 2010/01/26 22:14:36

If you want [b]older[/b] than 7 days, add "+"[code]
find /temp1 -mtime +7 -type f -exec rm -f {} \;[/code]

For 7 days or older
[code]
find /temp1 -mtime +6 -type f -exec rm -f {} \;[/code]

And I'd test first with "rm -i". :-)

michaelnel
Posts: 1478
Joined: 2006/05/29 16:50:11
Location: San Francisco, CA

Delete files older than 7 days?

Post by 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.

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Delete files older than 7 days?

Post by pschaff » 2010/01/26 22:26:46

Good point:[code]
find /temp1 -mtime +7 -type f -ls
OR
find /temp1 -mtime +7 -type f -exec ls -l {} \;[/code]

Post Reply