coreutils
[Top][All Lists]
Advanced

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

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


From: Lion Yang
Subject: 回复: 'find' do multi path search be completed and output once at a time
Date: Sun, 25 Oct 2020 11:21:59 +0800

‘find’ is essentially a recursively visiting-evaluation loop. It is supposed to 
print every result matches the expression immediately (or alternatingly to 
those sub-expressions, you may say), therefore it has the best performance.

Am I correct in saying that what you want to do is deferring ‘results’, actions 
or side-effects to the end of searching?

This is not what ‘find’ good at, and it implies a buffer to keep the 
intermediate results.
In case you’re avoiding to simply do the ‘find’ twice, from a performance point 
of view, I’d like to suggest tagging those results, sorting them later (ie. 
piping to ‘sort’, which does has a buffer internally) and finally cutting out 
tags:

find /usr -name sh -printf 'a:%p\n' -o -name gcc -printf 'b:%p\n'

b:/usr/bin/gcc
a:/usr/bin/sh
b:/usr/lib/gcc
a:/usr/lib/klibc/bin/sh
b:/usr/share/bash-completion/completions/gcc
a:/usr/share/bash-completion/completions/sh
b:/usr/share/doc/gcc
b:/usr/share/doc/gcc-9-base/gcc

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

/usr/bin/sh
/usr/lib/klibc/bin/sh
/usr/share/bash-completion/completions/sh
/usr/bin/gcc
/usr/lib/gcc
/usr/share/bash-completion/completions/gcc
/usr/share/doc/gcc
/usr/share/doc/gcc-9-base/gcc


reply via email to

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