bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #54730] Add additional valuable example of find -quit


From: Bernhard Voelker
Subject: [bug #54730] Add additional valuable example of find -quit
Date: Thu, 27 Sep 2018 03:19:27 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0

Follow-up Comment #4, bug #54730 (project findutils):

I agree.  I'm trying to find a good example.

What about the following?

  ---------------------------------------------------------------------------
  Find the name of a file in the current directory (and below) which contains
  the word "needle", and stop when the first such file is found.

    # Prepare 4 files, 2 of them contain the word "needle".
    $ touch a b c d    
    $ echo needle > b
    $ echo needle > dc

  Without -quit, 'find' would call 'grep' for every file (and there's
  currently no option to make 'grep' stop after a match across files):

    $ find -type f \
        -printf 'Checking: %p ...\n'  \
        -exec grep -FH needle '{}' \;
    Checking: ./c ...
    ./c:needle
    Checking: ./d ...
    Checking: ./a ...
    Checking: ./b ...
    ./b:needle

  With -quit, 'find' stops after the first match:

    $ find -type f \
        -printf 'Checking: %p ...\n' \
        -exec grep -FH needle '{}' \; \
        -quit
    Checking: ./c ...
    ./c:needle
  --------------------------------------------------------------------------




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?54730>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]