[ale] bash script
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Tue Sep 11 13:07:24 EDT 2007
On Tue 2007-09-11 10:18:17 -0400, Marvin, International Martian of Mystery wrote:
> I'd like some feedback/critique for a script I'm running as a cron job
> daily on a box I administrate. It's supposed to delete all the files it
> finds that are 5 days or older.
you don't say what other directories there are under
/var/www/zm/events. For example, are you deliberately skipping
events/{4,7,8} for some reason?
Also, modern versions of GNU find have a -delete action [0].
i'm not entirely sure this does what you want, but i think it might
be:
find /var/www/zm/events/{1,2,3,5,6,9,1{0,1,2,3,4,5}} -mtime +5 -a -type f -a ! -name '*.log' -delete
(entirely untested, i'm afraid)
notes:
* i used -mtime +5 instead of -mtime 5 to catch files modified > 5
days ago.
* i'm explicitly representing the conjunction of expressions in the
find statement (with -a), because i'm not confident that
conjunction is the default case.
* i moved the negated test (! -name '*.log') to the end to make sure
the negation doesn't apply to anything else. Other folks more
confident in their knowledge of find's operator precedence might
not care.
* i've added a test only for normal files (-type f), since you say
you want to delete files. this avoids deleting subdirs, etc.
* you can test this command by replacing -delete with -print, if you
like.
* if you really want to do this for all subdirs, not just the ones
specified above with curly-brace expansion, it'd probably be
simpler and more robust to begin the above command with:
find /var/www/zm/events/*
hth,
--dkg
[0] https://www.debian-administration.org/users/Steve/weblog/176
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 826 bytes
Desc: not available
More information about the Ale
mailing list