Operating System - Linux
1756743 Members
2588 Online
108852 Solutions
New Discussion юеВ

Re: removing files older than 10 days

 
p7
Frequent Advisor

removing files older than 10 days

hi all

we have a directory that the client dumps many reports into daily but its variable day by day (hundreds to few). to save space, they want me to keep only files that have been created in the last 7 days and delete
everything else in that directory.

here is the command i have:
find /col1ap01/metafile/metarprt/completed -type f -mtime +7 -exec|xargs rm

is that look ok or is there a better way
u mite know of?

thx in advance

4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: removing files older than 10 days

Hi:

Drop the '-exec' since you are passing the stream onto 'xargs'.

# find /col1ap01/metafile/metarprt/completed -type f -mtime +7 | xargs rm

Also, there is no such thing as a "creation" date in Unix. Thc closest you get is the last 'modification" timestamp ('mtime') which will coincidently equal a creation point at the moment of creation.

Regards!

...JRF...
Sundar_7
Honored Contributor

Re: removing files older than 10 days

Why do you even need xargs ? I dont believe that can be efficient than using exec

# find /col1ap01/metafile/metarprt/completed -type f -mtime +7 -exec rm {} \;

Learn What to do ,How to do and more importantly When to do ?
Patrick Wallek
Honored Contributor

Re: removing files older than 10 days

Actually xargs is MORE efficient than the '-exec' option in find.

The '-exec' option will spawn a separate process for each rm to remove each file. xargs works with groups of files, so you don't spawn as many processes.
James R. Ferguson
Acclaimed Contributor

Re: removing files older than 10 days

Hi:

> Patrick noted, "Actually xargs is MORE efficient than the '-exec' option in find."

However, if you are running 11i *and* you use '-exec command \+' instead of '-exec command \;' then the '-exec' collects multiple arguments much in the fashion of 'xargs' leading to a vast improvement in performance!

Regards!

...JRF...