Quick question abt find (Unix) and it's params

statik213

Golden Member
Oct 31, 2004
1,654
0
0
I want to find and delete files in a directory that are older than x days. I've looked at man and I want to make sure I have the correct interpretation of it before I delete these files.
If I do this:
$> find ./ -mtime +10 -type f
would that find all files older than 10 days?

then I'd do:
$> rm `find ./ -mtime +10 -type f`
 

ttown

Platinum Member
Oct 27, 2003
2,412
0
0
your syntax will start at root >SCARY< and find all files modified more than 10 days ago

you could do: find / -mtime +10 -type f -print| xargs rm

just typing that gets me anxious.... It will delete all files on your system that aren't "new".
Do that as user "root", and you'll be toast.

I think you might be thinking "." instead of "/".

Also, before I'd even think about doing such a thing, I'd do a "find / -mtime +10 -type -f -print" -- and look to make sure it makes sense.
I've learned the hard way to be extra cautious with the "rm" command... ;)
edit: syntax correction -- added "-print" to the find, before the pipe to xargs
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: ttown
your syntax will start at root >SCARY< and find all files modified more than 10 days ago

The ./ means it starts where ever he is, although he doesn't need the slash.

From the find man page I have this looks right:
find . -mtime 10 -type f -exec rm {} \;
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
Didn't think to use the exec arg.
I just did a rm`find ....`

BTW for future reference, do questions like this belong to this forum or the Operation System forum?