Re: File delete script not working



On 2006-08-19, Allen Kistler wrote:
mydejamail@xxxxxxxxxxx wrote:
I having a problem applying this script, it just doesn't seem to work.

The purpose is to delete all files over 30 days old. The directories
are 1,2,3,4,5.

Can anyone who knows about find and xargs please help.
It does not from the command line or a cron job.


cd /var/www/html/zm/events
find 1 -type f -mtime +30 | xargs rm -f
find 2 -type f -mtime +30 | xargs rm -f
find 3 -type f -mtime +30 | xargs rm -f
find 4 -type f -mtime +30 | xargs rm -f
find 5 -type f -mtime +30 | xargs rm -f

Why not:

find [12345] -type f -mtime +30 -exec rm -f {} \;

Because that would be very slow, because it calls rm for every file
found. If you have the latest version of find, this will be much
faster:

find 1 2 3 4 5 -type f -mtime +30 -exec rm -f {} +

Otherwise:

find 1 2 3 4 5 -type f -mtime +30 -print0 | xargs -0 rm -f

(But we still don't know what the OP's problem was.)

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages

  • Re: calculating the time difference.
    ... On 2006-08-08, aarcee wrote: ... My purpose is simple. ... for "date arithmetic" and read the FAQ: ... Shell Scripting Recipes: ...
    (comp.unix.shell)
  • Re: Man vs. Info: documenting the software
    ... reference when there's already one in the Info manual? ... What's the purpose of a separate Info manual when there's a ... Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)
  • Re: weird process
    ... >> used to generate printer status for some purpose. ... >> We don't use AIX's printing, so I cannot say whether it is normal for ... It looks to me like you have a cron job running ... that checks the status of print queues. ...
    (comp.unix.aix)
  • Re: File delete script not working
    ... The purpose is to delete all files over 30 days old. ... Can anyone who knows about find and xargs please help. ... It does not from the command line or a cron job. ...
    (comp.os.linux.misc)
  • Re: File delete script not working
    ... The purpose is to delete all files over 30 days old. ... Can anyone who knows about find and xargs please help. ... It does not from the command line or a cron job. ...
    (comp.os.linux.misc)