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

Re: File path caching?



*-Chris <chris@ormond.unimelb.edu.au>
|
| I've got another weird problem which is kind of annoying.
| 
| Say I have a program in /usr/bin, called fred for example.  I can run
| fred and everything is fine.
| 
| Then I create a file in /usr/local/bin, which is also called fred (say a
| wrapper for the real one).  Since /usr/local/bin is earlier in my path
| it should run first.
| 
| However when I try and run fred, it still runs the original version in=20
| /usr/bin, until I log out and log back in again.
| 
| Also, if I log out and back in I can run /usr/local/bin/fred, but if I then
| delete that program and try running fred again, I get a "file not found" er=
| ror,
| despite there being a executable called fred in /usr/bin.
| 
| Can anyone explain why this happens?

Yes. You are encountering what is called a the command hash table.

Let's say you type 'fred'. If your shell (bash?) were to search all
the directories in your path it could take a long time for each command.
Bash solves this by keeping a hash table of previous commands. Then,
whenever you type 'fred', bash first has a look in the table to see if it
has found that command earlier. If it has, then it uses the same file
again, and doesn't bother looking for others.

You can see what's in the table with the builtin command 'hash'.
What you need to do is to type 'hash -r', which clears the table. This
will allow bash to search for 'fred' in the path, not in the hash table.

-- 
.elOle.


Reply to: