[Sussex] Sussex Digest, Vol 387, Issue 1

David Binderman dcb314 at hotmail.com
Tue Sep 20 17:58:31 UTC 2011



Hello there,

Fay writes:
> $ find /home/fay/ -name '*~' -exec rm '{}' ; -print

$ find /home/fay -type f -name '*~' -print | grep -v 'whatever pattern you want' | xargs rm

sounds close to what you want. Even closer might be

$ find /home/fay -type f -name '*~' -print | fgrep -v '/home/fay/.' | xargs rm

Suggest test it out first, though.

$ find /home/fay -type f -name '*~' -print | fgrep -v '/home/fay/.' |  more

> On a different tack, although there isn't a whole directory tree I 
> need to ignore this time, so -prune doesn't apply, I'd like help on 
> this one too, please. In the interests of future searches, I would 
> like to know how to use the find command when I want to exclude, say, 
> two complete directories, "dir1" and "dir2" when searching for a 
> filename containing the string 'form'. Would I have to type the -prune
> once for each directory and what would the finished command look like?

The method I've given, using xargs, can have anything like grep, fgrep, egrep, sed, perl or
awk after the find, to restrict the list of filenames. Powerful, I find.

Regards

David Binderman

I first met Unix 30 years ago - a lot of this regexp technology is even older.

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/sussex/attachments/20110920/09adb93a/attachment.htm>


More information about the Sussex mailing list