Re: [PATCH v9] scripts/bash_aliases: Add useful functions

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

 





On 3/1/21 11:19 AM, Stefan Puiu wrote:
On Sat, Feb 27, 2021 at 7:16 PM Alejandro Colomar (man-pages)

I've always used find -name, I think most of the time it's enough. But
I can understand that people might prefer writing certain snippets in
a certain way, and you need to be comfortable with scripts you are
maintaining.

Yes

Actually, as far as I can tell there's not much difference
performance-wise between the two, as far as I can tell. At least when
searching the kernel source on my Linux VM. So it seems I'm wrong on
that point:

stefan@spuiu-vm:~/rpmbuild/BUILD/kernel-3.10.0-1160.2.2.el7/linux-3.10.0-1160.2.2.el7.x86_64$
time ( find . | grep '\.c' &>/dev/null )

real    0m0.076s
user    0m0.031s
sys     0m0.046s
stefan@spuiu-vm:~/rpmbuild/BUILD/kernel-3.10.0-1160.2.2.el7/linux-3.10.0-1160.2.2.el7.x86_64$
time ( find . -name  '*.c' &>/dev/null )

real    0m0.088s
user    0m0.016s
sys     0m0.066s

It seems that in real time, piping to grep is even faster than using find options :-)

Nevertheless, pcregrep is the bottleneck in these functions. So I guess it would make absolutely no difference.



Well, I understand the sentiment in those texts, but I would argue
that finding files by name is a core functionality of find :).

Yes, it is.  However, I think the following applies to grep and find:

"The use of cat to feed a single input file to a program has to some degree superseded the shell’s < operator, which illustrates that general-purpose constructs --like cat and pipes-- are often more natural than convenient special-purpose ones." [Program design in the UNIX(TM) environment]

At least to me, knowing the more general-purpose grep, is easier than learning the special purpose find -name :-)

However, the filename options to find may be necessary in some specific cases, so I'm not blaming them, only their syntax. And as long as my use cases are simple enough to work with grep, I'll keep using it.

It's
true that other extra functionality might not be exactly warranted,
and yes, '-print' feels kind of weird.

Thanks for bearing with me,
Stefan.


You're welcome!  Thanks for commenting on my scripts! :-}

Cheers,

Alex

--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux