Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Oct 1998 09:02:31 -0700 (PDT)
From:      David Wolfskill <dhw@whistle.com>
Cc:        freebsd-newbies@FreeBSD.ORG
Subject:   Re: First commands
Message-ID:  <199810061602.JAA06420@pau-amma.whistle.com>
In-Reply-To: <Pine.LNX.3.96.981006153655.21725B-100000@fire.dreams.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
>Date: Tue, 6 Oct 1998 15:39:56 +0300 (EET DST)
>From: Viljo Hakala <vipe@terafox.fi>

>> One I was surprised to see on the list is "locate" -- I don't think
>> I'd ever heard of it; I'm fairly certain I've never used it.  (Just
>> checked a Solaris 2.5 system; no such command.  Maybe "locate" is
>> FreeBSD (or 4.4 BSD) -specific?)

>Locate comes from 4.4. BSD tree.

Fair enough; my experience wich 4.4BSD(-derived) systems is limited.

>You may have found on Sun platforms that there are 'which' and
>'whereis' commands, which are both similar to 'locate'.

Well; my perception is somewhat different.

In csh (& tcsh), "which" invokes (another "csh" process) to determine the
full pathname of a given command.  (I happened to notice this when I
placed a "which" invocation inside my ~/.cshrc -- it sourced .cshrc all
over again, and if that's not properly controlled, an endless recursion
may follow.)  (There's a Perl script in /usr/bin/which, but csh & tcsh
don't use it.) (*)  BTW, I find "which" especially useful if I'm about
to issue a command as root.  Another nice thing about "which" is that if
the command is found, it merely returns the pathname, so doing something
like:

	ls -l `which ls`

is a reasonable way to see some trivia about the version of the "ls"
command that one happens to be executing (such as its size and when it
was last modified).

"whereis", on the other hand, looks in certain "standard" places for
executables or man pages or sources, and reports the information is a
format that is more suitable for human parsing than for insertion in
commands.

"locate" seems to rely on a database being constructed, and reports the
results of a search through that database (vs. what happens to be on the
file system(s) as of the time that "locate" is invoked).

On the other hand, "find" prowls through the filesystem(s) in question,
looking for whatever you asked for, and does whatever you specified;
what it reports is based on the status of the filesystem(s) at the time
you issue the command (vs. whenever a database-update program ran).

These are all different tools for different needs.


Footnotes:
---------
* The reason I was doing such a pathological thing as invoking "which"
within ~/.cshrc is that I have /bin/csh as my login shell, but I
actually prefer to use /usr/local/bin/tcsh.  Although I could change my
login shell to tcsh, that would be a problem if I login to a machine
that can't get to our (common) /usr/local, or if the NFS server is
having problems, or several other things.  Further, tcsh is basically a
superset of csh.  So I wrote some code in ~/.cshrc that would check to
see if this reading of ~/.cshrc is being done by csh (vs. tcsh), and if
so, would check to see if tcsh is available, and if so, would "exec
tcsh".

david
-- 
David Wolfskill		UNIX System Administrator
dhw@whistle.com		voice: (650) 577-7158	pager: (650) 371-4621

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-newbies" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810061602.JAA06420>