From: Timur Tabi on
I have the following directories and files:

$ find .
..
../A
../A/a.pdf
../B
../B/b.pdf
../B/b.txt
../C
../C/c.pdf

That is, three directories (A, B, and C), and each one has one PDF
file in it. Directory B also has b.txt.

I'm trying to get the find command to generate this output:

../B/b.pdf
../C/c.pdf

That is, I want a list of all PDF files in all subdirectories,
*except* the A directory.

How can I do that with the find command? I tried this:

$ find . -name A -prune -o -name "*.pdf"

But that gives me this output:

../B/b.pdf
../A
../C/c.pdf

How do I get it to skip "A" entirely?
From: Harry on
On Jul 9, 3:22 pm, Timur Tabi <ti...(a)tabi.org> wrote:
> I have the following directories and files:
>
> $ find .
> .
> ./A
> ./A/a.pdf
> ./B
> ./B/b.pdf
> ./B/b.txt
> ./C
> ./C/c.pdf
>
> That is, three directories (A, B, and C), and each one has one PDF
> file in it.  Directory B also has b.txt.
>
> I'm trying to get the find command to generate this output:
>
> ./B/b.pdf
> ./C/c.pdf
>
> That is, I want a list of all PDF files in all subdirectories,
> *except* the A directory.
>
> How can I do that with the find command?  I tried this:
>
> $ find . -name A -prune -o -name "*.pdf"
>
> But that gives me this output:
>
> ./B/b.pdf
> ./A
> ./C/c.pdf
>
> How do I get it to skip "A" entirely?

$ find . -type f
../A/a.pdf
../B/b.pdf
../C/c.pdf

$ find [^A] -name '*.pdf'
B/b.pdf
C/c.pdf
From: Harry on
On Jul 9, 3:22 pm, Timur Tabi <ti...(a)tabi.org> wrote:
> I have the following directories and files:
>
> $ find .
> .
> ./A
> ./A/a.pdf
> ./B
> ./B/b.pdf
> ./B/b.txt
> ./C
> ./C/c.pdf
>
> That is, three directories (A, B, and C), and each one has one PDF
> file in it.  Directory B also has b.txt.
>
> I'm trying to get the find command to generate this output:
>
> ./B/b.pdf
> ./C/c.pdf
>
> That is, I want a list of all PDF files in all subdirectories,
> *except* the A directory.
>
> How can I do that with the find command?  I tried this:
>
> $ find . -name A -prune -o -name "*.pdf"
>
> But that gives me this output:
>
> ./B/b.pdf
> ./A
> ./C/c.pdf
>
> How do I get it to skip "A" entirely?


$ find . \( -name A -prune -a -type f \) -o -name '*.pdf'
../B/b.pdf
../C/c.pdf
From: Alan Curry on
In article <492dea4f-0c48-4ba5-9090-1088cfbf1092(a)c20g2000vbg.googlegroups.com>,
Timur Tabi <timur(a)tabi.org> wrote:
>
>$ find . -name A -prune -o -name "*.pdf"
>
>But that gives me this output:
>
>./B/b.pdf
>./A
>./C/c.pdf
>
>How do I get it to skip "A" entirely?

The luxury of modern find(1) has made us lazy.

What you meant was:
find . -name A -prune -o -name "*.pdf" -print
in which the -print binds to the -name "*.pdf" because of the precedence of
the AND operation over the OR.

You left out the -print because you've got the idea that it's unnecessary. So
you got the POSIX-required implicit -print, which binds to the entire
expression, like this:
find . \( -name A -prune -o -name "*.pdf" \) -print

So the A got pruned (nothing under it was checked), but the pruning operation
returns true, the whole parenthesized expression is true, and -print gets run
for A.

--
Alan Curry