help with command line deletion

Norman Gray norman at astro.gla.ac.uk
Fri Apr 20 02:52:09 PDT 2007


On 2007 Apr 20 , at 02.38, LuKreme wrote:

>> This sort of thing is why I prefer the general technique of piping  
>> 'find's output to something else to do the work (in this case, the  
>> deletion).  That way, I don't have to worry about whether this  
>> Unix's find has some funky flag or not, and I don't have to read  
>> the find manpage (again) to remind myself of the syntax, and try  
>> to remember how I'm supposed to escape the {}, and whether I need  
>> the \; or not, and whether -delete deletes a directory's contents  
>> before the directory itself.
>
> Yep, but it's not that simple, you can't simply pipe to rm, so you  
> have to learn a whole different syntax involving -print0 for find  
> and xargs -0 to process the list, so you're really not gaining much,

I agree that the xargs technique is non-obvious, but it only has to  
be learned once, after which it's useful in a lot more cases.  What  
if I want to grep a subset of files, for example?

% find . -name \*.log | xargs grep wibble

Things of that generality could of course be handled by the -exec  
'find' flag, but those command lines always look just damn ugly!   
It's the 'while read line' technique that's the really powerful one,  
though: rename in depth-first order all the files in .indelible-info  
directories which don't have an 'a' in their name -- that's a one- 
liner, I'd think.

> especially since as it turns out, -delete has been part of OS X  
> since at least 10.2

True.  But can you remember, without looking it up, whether it's also  
part of Linux, Solaris and DUX?

All the best,

Norman


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




More information about the MacOSX-admin mailing list