4

Why does the Linux program which require you to refresh the shell (e.g. type tcsh in the terminal) to see new programs installed in your path??

I was baffled why I couldn't access a program, which had the same permissions as other programs in usr/local/bin, which which could clearly see.

Can someone explain how this works to me in layman's terms?

2 Answers 2

7

Try rehash

man tcsh says

   rehash  Causes  the internal hash table of the contents of the directo-
           ries in the path variable to be recomputed.  This is needed  if
           new  commands  are  added  to directories in path while you are
           logged in.  This should be necessary only if you  add  commands
           to  one  of  your  own  directories, or if a systems programmer
           changes the contents of one of the  system  directories.   Also
           flushes the cache of home directories built by tilde expansion.

In layman's terms: tcsh wants to provide a snappy response, so it builds an internal table (a hash table presumably) of commands and where they are to be found. It presumably does this at start up. Unfortunately it doesn't have any mechanism to notice when you or an administrator do something that would need that table to be updated.

This is one of many reasons why I prefer ksh or bash to csh derivatives.

5
  • 1
    Does one have to do this every time a new program is installed through e.g. the package manager as well? Apr 13, 2012 at 15:55
  • 2
    @DanielAndersson: Almost certainly, if you use tcsh. Apr 13, 2012 at 15:58
  • *shivers* :-) Apr 13, 2012 at 16:06
  • I typically use Bash, so maybe that's why I'd never noticed this before... apparently tcsh was my default shell for the stock terminal shortcut in CentOS 6.2... (or at least the version I had). :) Apr 13, 2012 at 17:20
  • @DanielAndersson This shouldn't be necessary if it's a new command being installed that didn't exist before. Feb 18, 2015 at 21:03
0
$ which test
/usr/bin/test
$ ls ~/bin/test
ls: cannot access bin/test: No such file or directory
$ touch ~/bin/test
$ chmod 755 ~/bin/test
$ which test
/home/daniel/bin/test
$

No shell refresh needed using Bash, so it is not related to which in itself. There must be other variables at play.

1
  • Apparently tcsh works differently (see above)... Apr 13, 2012 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .