Skip to main content
edited body
Source Link
user373503
user373503

My GNU findutils (FSF 2015) says:

-prune
   True; 
   if the file is a directory, do not descend into it.
   If -depth is given, false; no effect.
   Because -delete implies -depth, you cannot usefully use -prune and -delete together.

And Posix:

-prune
    The primary shall always evaluate as true;
    it shall cause find not to descend the current pathname if it is a directory. 
    If the -depth primary is specified, the -prune primary shall have no effect.

I only changed the linebreaks. Two things are remarkable?:

Are not both totally ignoring -prune's main effect? i.e. to "collect" the expressions to the left, and leave the rest to a -o - connected expression to the right?

With GNU's man page you at least get directed to an example:

-name pattern
    Base of ...
    ...
    ...   
    To ignore a directory and the files under it, use -prune;
    see an example in the description of -path.
    ...

Well there is a simple example with find . EXPR -prune -o -print. This automatically raises the question why find . prints anything at all.

In retrospect, nicely laid out, it is all there.

Now the related Q:

How are these two -prune explanations (GNU vs. POSIX) related?

To me it looks like posix took a dry technical list with one useful hint and turned it into jargon prose for no reason. It is even misleading.

Because in the end both explanations leave you asking:

Why do I need -o after -prune, if it always returns true?

Here is a tested example: I have some mountpoints to skip, and also want to skip the ramdisk "0" (a zero), and want to list all files containing "test",

find . -xdev -name "0" -prune -o -name '*test*'

Like this it works; it also includes a line ./0, which is actually interesting.

Without the prune-o-trick, I cannot make it work, even with explicit -print.

My GNU findutils (FSF 2015) says:

-prune
   True; 
   if the file is a directory, do not descend into it.
   If -depth is given, false; no effect.
   Because -delete implies -depth, you cannot usefully use -prune and -delete together.

And Posix:

-prune
    The primary shall always evaluate as true;
    it shall cause find not to descend the current pathname if it is a directory. 
    If the -depth primary is specified, the -prune primary shall have no effect.

I only changed the linebreaks. Two things are remarkable?

Are not both totally ignoring -prune's main effect? i.e. to "collect" the expressions to the left, and leave the rest to a -o - connected expression to the right?

With GNU's man page you at least get directed to an example:

-name pattern
    Base of ...
    ...
    ...   
    To ignore a directory and the files under it, use -prune;
    see an example in the description of -path.
    ...

Well there is a simple example with find . EXPR -prune -o -print. This automatically raises the question why find . prints anything at all.

In retrospect, nicely laid out, it is all there.

Now the related Q:

How are these two -prune explanations (GNU vs. POSIX) related?

To me it looks like posix took a dry technical list with one useful hint and turned it into jargon prose for no reason. It is even misleading.

Because in the end both explanations leave you asking:

Why do I need -o after -prune, if it always returns true?

Here is a tested example: I have some mountpoints to skip, and also want to skip the ramdisk "0" (a zero), and want to list all files containing "test",

find . -xdev -name "0" -prune -o -name '*test*'

Like this it works; it also includes a line ./0, which is actually interesting.

Without the prune-o-trick, I cannot make it work, even with explicit -print.

My GNU findutils (FSF 2015) says:

-prune
   True; 
   if the file is a directory, do not descend into it.
   If -depth is given, false; no effect.
   Because -delete implies -depth, you cannot usefully use -prune and -delete together.

And Posix:

-prune
    The primary shall always evaluate as true;
    it shall cause find not to descend the current pathname if it is a directory. 
    If the -depth primary is specified, the -prune primary shall have no effect.

I only changed the linebreaks. Two things are remarkable:

Are not both totally ignoring -prune's main effect? i.e. to "collect" the expressions to the left, and leave the rest to a -o - connected expression to the right?

With GNU's man page you at least get directed to an example:

-name pattern
    Base of ...
    ...
    ...   
    To ignore a directory and the files under it, use -prune;
    see an example in the description of -path.
    ...

Well there is a simple example with find . EXPR -prune -o -print. This automatically raises the question why find . prints anything at all.

In retrospect, nicely laid out, it is all there.

Now the related Q:

How are these two -prune explanations (GNU vs. POSIX) related?

To me it looks like posix took a dry technical list with one useful hint and turned it into jargon prose for no reason. It is even misleading.

Because in the end both explanations leave you asking:

Why do I need -o after -prune, if it always returns true?

Here is a tested example: I have some mountpoints to skip, and also want to skip the ramdisk "0" (a zero), and want to list all files containing "test",

find . -xdev -name "0" -prune -o -name '*test*'

Like this it works; it also includes a line ./0, which is actually interesting.

Without the prune-o-trick, I cannot make it work, even with explicit -print.

Source Link
user373503
user373503

find and -prune, and GNU and POSIX explanations

My GNU findutils (FSF 2015) says:

-prune
   True; 
   if the file is a directory, do not descend into it.
   If -depth is given, false; no effect.
   Because -delete implies -depth, you cannot usefully use -prune and -delete together.

And Posix:

-prune
    The primary shall always evaluate as true;
    it shall cause find not to descend the current pathname if it is a directory. 
    If the -depth primary is specified, the -prune primary shall have no effect.

I only changed the linebreaks. Two things are remarkable?

Are not both totally ignoring -prune's main effect? i.e. to "collect" the expressions to the left, and leave the rest to a -o - connected expression to the right?

With GNU's man page you at least get directed to an example:

-name pattern
    Base of ...
    ...
    ...   
    To ignore a directory and the files under it, use -prune;
    see an example in the description of -path.
    ...

Well there is a simple example with find . EXPR -prune -o -print. This automatically raises the question why find . prints anything at all.

In retrospect, nicely laid out, it is all there.

Now the related Q:

How are these two -prune explanations (GNU vs. POSIX) related?

To me it looks like posix took a dry technical list with one useful hint and turned it into jargon prose for no reason. It is even misleading.

Because in the end both explanations leave you asking:

Why do I need -o after -prune, if it always returns true?

Here is a tested example: I have some mountpoints to skip, and also want to skip the ramdisk "0" (a zero), and want to list all files containing "test",

find . -xdev -name "0" -prune -o -name '*test*'

Like this it works; it also includes a line ./0, which is actually interesting.

Without the prune-o-trick, I cannot make it work, even with explicit -print.