[Top][All Lists]

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

Re: 'find' do multi path search be completed and output once at a time

From: Bernhard Voelker
Subject: Re: 'find' do multi path search be completed and output once at a time
Date: Sun, 25 Oct 2020 20:44:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2

On 10/25/20 2:22 AM, Budi wrote:
Can 'find'  do multi path search be completed and output once at a
time each in merely one execution/invocation

First of all, 'find' is not part of the GNU coreutils but instead maintained
in the GNU findutils package.  Thus, you'd better be off asking questions
where it tell you:

  $ find --help | tail -n5
  Please see also the documentation at
  You can report (and track progress on fixing) bugs in the "find"
  program via the GNU findutils bug-reporting page at or, if
  you have no web access, by sending email to <>.

Thus, I'm CCing the bug-findutils mailing list.

Second, I'm not sure from the above sentence what you mean by "multi path 

Problem is if done use -o to do the multi path search it'll show all
result in immediate time e.g:

find . -path *.sh -o -path *.c

The unquoted patterns *.sh and *.c are for sure a problem.
You should quote each of them like '*.sh' and '*.c'.

Furthermore, as you're only referring to the basename of each file processed,
you could use the -name test instead of -path (which matches against the full
path strings relative to the starting argument '.').



what needed is to output this, in one execution/invocation:



Is it possible

Ah, do you mean that you first want the result of the search for files matching 
and then those for searching for files matching '*.c'?

As Lion Yang already suggested, I'd do this by the well-known 
pattern, i.e., adding a marker to each pattern when printing, then sorting by 
pattern, and finally removing the pattern again.  Lion suggested something like:

  find .  -name '*.sh' -printf 'a:%p\n' -o -name '*.c' -printf 'b:%p\n' \
    | sort -s -t':' -k1,1 \
    | cut -d':' -f2-

Please note that the above will probably work in most of your cases, but will 
e.g. in the case a file name include a newline character ('\n').  You'd have to
cater for this by chosing the safer NUL '\0' character as separator between the
file names, and teaching the post-processing commands 'sort' and 'cut' to use
that as well (-z options); likewise for the part which consumes the final 

Have a nice day,

reply via email to

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