zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Lloyd Zusman <ljz@asfast.com>
Cc: zsh-users@sunsite.dk
Subject: Re: Emulating 'locate'
Date: Sat, 4 Oct 2003 12:48:44 +0200	[thread overview]
Message-ID: <20031004104844.GA50@DervishD> (raw)
In-Reply-To: <m365j6watm.fsf@asfast.com>

    Hi Lloyd :)

 * Lloyd Zusman <ljz@asfast.com> dixit:
> >>     locate() { print -l /**/*${^*}*{,/**/*} }
> >     Ok, it works like a charm... Thanks a lot, as always :)
> I might have missed something about this in the first part of the thread
> a couple weeks ago (those messages have already expired on my system),
> but in case it wasn't mentioned before, I want to point out that this
> function is _extremely_ slow in comparison to the standard 'locate'
> command.  It traverses through every accessible item on every accessible
> file system in order to check for a match.  On my server, it's literally
> thousands of times slower than using the standard 'locate'.

    Obviously: locate uses a database of names for doing the
'location'. Moreover, I don't know exactly if locate is faster than
doing a grep in the same database (uncompressed, of course... The
locate database is front-compressed, see find manual for details).

    The 'locate' command doesn't do any magic for being fast: the
price it pays is the need of a database, that may be outdated (so you
will miss files, or find nonexistent ones...). If you want reliable
results you have two options:

    - Use the zsh version, or a version with 'find'.
    - Update de database regularly. Very regularly, in fact. If files
are created and destroyed frequently, you will have to update the
database continously... On the average system, anyway, this is not an
issue, specially if you look for files that reside on 'stable' parts
of the system.
 
> I'm not sure how it compares to this:
>   locate() { find / -name "*${^*}*" -print }

    This is faster, IMHO, because AFAIK find uses a non-recursive
algorithm to recurse the hierarchy. Although I'm not sure about that
glob pattern you use, since it will be interpreted by find, not the
shell :?? The manual says you can use a shell pattern, but I'm not
sure about who interprets it. If it is find who interprets, then
${^*} won't work as expected. Using more ellaborate patterns is an
advantage of using the zsh version.

> Figuring this out is a very good learning experience for zsh. 
> However, I would not recommend installing this function for
> everyday use on a reasonably sized system.

    Of course ;))) But on small systems or when searching on a
limited set of directories, the zsh version, although slower, permits
more ellaborated searches, IMHO. And doesn't find false positives
(nonexistent files) nor misses files ;) But you're true, this is more
a learning experience than a function of real use. For it to be
useful, it must be rewritten to use a database, or something like
that...

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


  reply	other threads:[~2003-10-04 10:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20031001221753.GA23189@DervishD>
     [not found] ` <1031002023639.ZM22046@candle.brasslantern.com>
2003-10-02  8:03   ` DervishD
2003-10-02 14:29     ` Bart Schaefer
2003-10-02 15:53       ` DervishD
2003-10-02 17:08         ` Oliver Kiddle
2003-10-02 19:27           ` DervishD
2003-10-03 16:22     ` Lloyd Zusman
2003-10-04 10:48       ` DervishD [this message]
2003-10-04 13:48         ` Lloyd Zusman
2003-10-04 15:12           ` DervishD
2003-10-04 17:05             ` Lloyd Zusman
2003-10-04 21:35               ` DervishD
2003-10-04 16:37           ` Bart Schaefer
2003-10-04 19:33             ` Lloyd Zusman
2003-10-04 21:29               ` DervishD
2003-10-04 22:40               ` Bart Schaefer
2003-10-04 23:18                 ` Lloyd Zusman
2003-10-05 15:57                   ` Bart Schaefer
2003-10-06 13:37                     ` Lloyd Zusman

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=20031004104844.GA50@DervishD \
    --to=raul@pleyades.net \
    --cc=ljz@asfast.com \
    --cc=zsh-users@sunsite.dk \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).