All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Puiu <stefan.puiu@gmail.com>
To: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>,
	lnx-man <linux-man@vger.kernel.org>, Walter Harms <wharms@bfs.de>
Subject: Re: [PATCH v9] scripts/bash_aliases: Add useful functions
Date: Mon, 1 Mar 2021 12:19:41 +0200	[thread overview]
Message-ID: <CACKs7VAwN6_ibvEhNsnsNsS6PnncCmjGEuKuBs-P5qMXNw2Vww@mail.gmail.com> (raw)
In-Reply-To: <072ee0c3-f30f-9da3-1b3f-37b5bc095806@gmail.com>

Hi Alejandro,

On Sat, Feb 27, 2021 at 7:16 PM Alejandro Colomar (man-pages)
<alx.manpages@gmail.com> wrote:
[...snip]
> >> +       find * -type f \
> >> +       |grep '\.c$' \
> >> +       |sort -V \
> >> +       |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?\)" \
> >> +       |sed -E 's/^[^:]+:[0-9]+:/&\n/';
> >> +
> >> +       find * -type f \
> >> +       |grep '\.[ch]$' \
> >
> > Any reason not to use "find . -type f -name '*.[ch]'" when you need to
> > restrict the files you're looking at? I would expect that to be
> > faster.
>
> I don't like find syntax.  I never remember how all of its options work.
> grep is much simpler, and everyone knows how it works.
>
> find has: -[i]lname, -[i]name, -[i]path, -[i]regex, -[i]wholename
> I don't want to be reading the manual for all of them each time I use
> find.  grep does the same with optional -i and some simple regex which
> anyone could understand with some basic regex knowledge.

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.

>
> For the performance part, I don't know; but we might be surprised.  At
> most it might be a bit faster (nothing like 200%), but I care more about
> readability.

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

>
> I also avoid using find -exec option, and instead use xargs.  It's way
> simpler to understand, at least for me.
>
> See also:
> <http://doc.cat-v.org/unix/find-history>
> <http://harmful.cat-v.org/cat-v/>

Well, I understand the sentiment in those texts, but I would argue
that finding files by name is a core functionality of find :). 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.

  reply	other threads:[~2021-03-01 10:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 13:15 [PATCH] scripts/bash_aliases: Add useful functions Alejandro Colomar
2021-02-15 13:36 ` Alejandro Colomar (man-pages)
2021-02-15 20:31 ` Alejandro Colomar
2021-02-15 20:32 ` [PATCH v3] " Alejandro Colomar
2021-02-16 10:54   ` AW: " Walter Harms
2021-02-16 11:00     ` Alejandro Colomar (man-pages)
2021-02-18 18:47 ` [PATCH v4] " Alejandro Colomar
2021-02-18 19:33 ` [PATCH v5] " Alejandro Colomar
2021-02-18 21:17 ` [PATCH v6] " Alejandro Colomar
2021-02-19 14:13 ` [PATCH v7] " Alejandro Colomar
2021-02-19 14:22 ` [PATCH v8] " Alejandro Colomar
2021-02-19 14:32 ` [PATCH v9] " Alejandro Colomar
2021-02-20 14:35   ` Michael Kerrisk (man-pages)
2021-02-20 21:45   ` Michael Kerrisk (man-pages)
2021-02-27 15:09   ` Stefan Puiu
2021-02-27 17:16     ` Alejandro Colomar (man-pages)
2021-03-01 10:19       ` Stefan Puiu [this message]
2021-03-01 14:16         ` Alejandro Colomar (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACKs7VAwN6_ibvEhNsnsNsS6PnncCmjGEuKuBs-P5qMXNw2Vww@mail.gmail.com \
    --to=stefan.puiu@gmail.com \
    --cc=alx.manpages@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=wharms@bfs.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.