From: l1ngo@copper.denver.colorado.edu (Linh Ngo) Subject: Re: Binary locations Date: 26 Sep 1992 01:27:25 GMT
In article <y#sn22#.genie@netcom.com> genie@netcom.com (The Genie) writes:
>I've been using Linux for about 2 weeks now, and have found
>a small nit-picky problem. When I compile something
>or move a executable binary into a directory, Linux refuses
>to recognize the existence of the binary unless
>1) I source my .cshrc which includes paths
>2) The new binary must be located in the binary path.
>
>Is there a way for Linux to automatically recognize binaries
>and execute them in any directory besides those listed
>in the path + to recognize a new binary when placed in
>a directory (in essence, I have to source the .cshrc to
>tell Linux to check all the paths for all binaries).
[...]
You must tell the T-shell (tcsh) or C-shell (csh) about new files in
the directories specified by your path variable by typing:
rehash
These shells keep a hash table with the names of files in your
$path directories. 'rehash' tells the shell to rebuild its hash table;
A hash table is a quick way to look-up which directory contains a
certain file.
As for how to make the shell know about ALL files on your system,
this is not feasible. Without the path variable, the shell might
do one of two things to find executables (theoretically speaking):
1. It would only look in the current directory (this is not too useful).
2. It would have to search the entire filesystem(s) for the command:
a. If it must do it on-the-fly, imagine how long it would take to
search all the directories (e.g., find / -print)
b. If it keeps a hash table in memory, this table would take up
quite a bit of memory. Again, you'd have the 'rehash' problem
when you create/move/rename files, only a much much longer wait.
A big problem that both of these unlikely solutions have is a
security problem (e.g., someone plants an 'sl' program to delete your
files next time you mistype 'ls').
I prefer the hash table for speed (and a simple 'rehash' when necessary)
over the way the Bourne shell handles things: it searches the
directories in your path variable every time you type a command that
doesn't have a relative or absolute path in front of it.
Linh Ngo