help with command line deletion

Norman Gray norman at astro.gla.ac.uk
Tue Apr 17 02:38:30 PDT 2007


On 2007 Apr 17 , at 10.03, David Herren wrote:

> locate .indelible-info returns an enormously long list. I imagine  
> piping locate to some form of rm -R is the way to go, but the  
> potentially disastrous results of my misuse of that lead me here  
> for consultation...

Something like

% find . -name .indelible-info -print0 | xargs -0 rm -R

is the general pattern for this sort of thing.

However, I HAVE NOT TESTED THIS, and I'm not going to -- that's over  
to you, once you're clear what each bit is doing.  The -print0 and -0  
are there in case some paths have spaces in them.

If some of the problematic directories are inside other ones, then  
this will produce errors, because the list from 'find' will list  
parents before children.  In that case, you'll have to do something  
different, and the -0 trick won't work.  You'll need something like

% find . -name .indelible-info | sort -r | while read f; do rm -R $f;  
done

That'll reorder the list from 'find' so that children come before  
parents, and shows an alternative way to handle spaces in the list  
obtained from 'find'.

Be careful!

Norman


-- 
------------------------------------------------------------------
Norman Gray  :  http://nxg.me.uk
eurovotech.org  :  University of Leicester, UK




More information about the MacOSX-admin mailing list