[nycbug-talk] find exclude question

N.J. Thomas njt
Mon Oct 17 15:19:24 EDT 2005


* George Georgalis <george at galis.org> [2005-10-17 14:01:29 -0400]:
> > > i would like to run the following find /path/to/dir -atime +14 -- 
> > > exclude dir1,dir2 -exec rm -fr {} \ ;
> > > 
> > > i want to exclude dir1 and dir2 from this find
> >
> > You want "-prune", as in:
> >
> >    find /path/to/dir \( -path /path/to/dir/dir1 -o -path /path/to/dir/dir2\) -prune -o -print
> 
> Isn't that the oppisit of requested? eg prune returns the trimmings
> 
> find . ! \( -path '*/CVS' -prune \) 

hi George,

If I understand the OP correctly, he wanted to exclude dir1 and dir2
from his find action (deleting old directories). Also, if I understand
how find works (its been a while since I've read up on the man/info
page), -prune is a primary (the others are -print, -exec, etc.)

So to do what he wanted, he would have to have two primaries, one to
prune away the unnecessary dirs and the other to run his -exec.

I believe the full command he needs to run is something like this:

    find /path/to/dir \( -path /path/to/dir/dir1 -o -path /path/to/dir/dir2 \) -prune -o -atime +14 -exec rm -fr {} \ 

The way you are running find above may return the trimmings, but if my
reading of the man/info page is correct (its been a while since I've
looked at it), your statement is incomplete because it doesn't have a
primary after the -prune (-print or -exec).

But I didn't sleep at a Holiday Inn last night, feel free to correct
this. =-)

Thomas

-- 
N.J. Thomas
njt at ayvali.org
Etiamsi occiderit me, in ipso sperabo




More information about the talk mailing list