Delete files older than 7 days?
Delete files older than 7 days?
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
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
Re: Delete files older than 7 days?
find /temp1/* -mtime 7 -print -exec rm -f {} \;
Re: Delete files older than 7 days?
I try it and i looks like its working, but still files are in the folder
find /temp1/ -mtime 7 -print -exec rm -f {} \;
find /temp1/ -mtime 7 -print -exec rm -f {} \;
Re: Delete files older than 7 days?
use the asteric or:
find /temp1/ -mtime 7 -type f -print -exec rm -f {} \;
find /temp1/ -mtime 7 -type f -print -exec rm -f {} \;
Re: Delete files older than 7 days?
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 {} \;
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 {} \;
Re: Delete files older than 7 days?
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?
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?
- 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?
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]
Hence I would use --
[code]
[b]find /temp1 -mtime 7 -type f -exec rm -f \{\} \;[/b]
[/code]
-
- Retired Moderator
- Posts: 18276
- Joined: 2006/12/13 20:15:34
- Location: Tidewater, Virginia, North America
- Contact:
Re: Delete files older than 7 days?
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". :-)
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". :-)
-
- Posts: 1478
- Joined: 2006/05/29 16:50:11
- Location: San Francisco, CA
Delete files older than 7 days?
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.
-
- Retired Moderator
- Posts: 18276
- Joined: 2006/12/13 20:15:34
- Location: Tidewater, Virginia, North America
- Contact:
Re: Delete files older than 7 days?
Good point:[code]
find /temp1 -mtime +7 -type f -ls
OR
find /temp1 -mtime +7 -type f -exec ls -l {} \;[/code]
find /temp1 -mtime +7 -type f -ls
OR
find /temp1 -mtime +7 -type f -exec ls -l {} \;[/code]