[TriLUG] `find -delete` not deleting

Steve Litt via TriLUG trilug at trilug.org
Tue Sep 6 13:03:55 EDT 2016


On Tue, 6 Sep 2016 16:33:51 +0000 (GMT)
Joseph Mack NA3T via TriLUG <trilug at trilug.org> wrote:

> On Tue, 6 Sep 2016, Lance A. Brown via TriLUG wrote:
> 
> > TEST this before using!
> >
> > Something like:
> >
> > find $top_dir -mtime +7 > /tmp/delete.$$ && xargs /bin/rm -rf <
> > /tmp/delete.$$ && /bin/rm /tmp/delete.$$  
> 
> oh me oh mi
> 
> > That way you capture the list of files/directories to delete to a
> > file, delete them, then remove that file.  This avoids changing the
> > mtime on the directories.  
> 
> Hi Lance,
> 
> I'm trying this
> 
> find $top_dir -maxdepth 2 -mtime +7 -type d -exec rm -rf  {} \;
> 
> the directories I want to delete are 2 levels down from $top_dir, I
> assemble the list of directories and then `rm -rf` them.
> 
> I don't have any directories left from 7 days ago (I scrubbed them),
> but if I change the +7 to +6, then when I run the above command, I
> don't have any directories from 6 days ago with today's date.
> 
> I'll watch it for the next couple of days.

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

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




More information about the TriLUG mailing list