[TriLUG] `find -delete` not deleting

Steve Litt via TriLUG trilug at trilug.org
Tue Sep 6 21:23:53 EDT 2016


On Tue, 6 Sep 2016 14:15:53 -0400
Aaron Morrison <ae4ko at amsat.org> wrote:

> > On Sep 6, 2016, at 13:03, Steve Litt via TriLUG <trilug at trilug.org>
> > wrote:
> > 
> > 
> > 
> > Why are you using find? Your directories are already named for
> > datestamps. Just have the cron job's shellscript calculate 7 days
> > ago (let's say 8/27/2016), then do rm -rf whatever/20160827.
> > 
> > SteveT
> >   
> 
> So what if cron misses its trigger?  E.g. On a laptop that is off or
> sleeping? If so then this will miss removing that week old directory
> and no subsequent cron execution will remove it either. (I'll grant
> that some cron implementations try to recognize missed triggers and
> those may work)
> 
> The find method will recover from that case and in fact may be more
> flexible if the conditions change. ( only want to remove symlinks? No
> problem.  )

In thaaaaaat case, since all directories at that level are in yyyymmdd
format:

for fname in 2???????; do
  if test $timestamp > $fname; then
    rm -rf $fname
  fi
done

It might sound like I'm being obstreperous, but there are some things I
just won't do:

* Control anything dangerous with find
* Do anything dangerous fed by xargs
* rm -rf $envvar unless I have absolute control over $envvar
* rm -rf .

Actually, thinking more about it, I'd just

rm -rf $timestamp

and then issue a report on any too-old directories, so if such an edge
case happens, I can manually delete them.

SteveT

Steve Litt 
September 2016 featured book: Twenty Eight Tales of Troubleshooting
http://www.troubleshooters.com/28




More information about the TriLUG mailing list