[nycbug-talk] find exclude question
George Georgalis
george
Mon Oct 17 18:05:44 EDT 2005
On Mon, Oct 17, 2005 at 03:19:24PM -0400, N.J. Thomas wrote:
>* George Georgalis <george at galis.org> [2005-10-17 14:01:29 -0400]:
>>
>> 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).
...well my use of ! has made the syntax more comprehensible for
me. But it doesn't work for testing the OP's situation, which
requires -o, instead you need something like this
find . ! \( \( -path ./dir/dir2 -o -path ./dir/dir1 \) -prune \)
Matter of taste, I find "! ( -path ... -prune )" easier to read
than "( -path ... ) -prune -o" but with the extra paren in there
to support "-o -path ...", it gets messy. I checked the man...
-print is the default if there is no primary.
But there is another problem. if you exclude ./dir/dir2 and
./dir/dir2 but do -atime +14, who's to say you're not going to
rm -fr ./dir?
The OP's question has been trimmed, but there are several ways to
hack around this, including using "rm $(find ... | grep -v ...)",
-mindepth, -maxdepth or -type f. On another occasion I've checked
and using -prune is a _lot_ faster than using grep -v.
Maybe Steve will post what he comes up with?
// George
--
George Georgalis, systems architect, administrator <IXOYE><
http://galis.org/ cell:646-331-2027 mailto:george at galis.org
More information about the talk
mailing list