..bits & bytes teleported

Wednesday Jul 16, 2008

Shells cache the commands which you have executed so as to save the time required to search your PATH every time you execute it. Type 'hash' in your terminal and you will see something like:
$ hash

hits    command
  1    /usr/bin/which
  2    /usr/local/bin/log4cpp-config
  1    /usr/bin/gnome-screensaver
  1    /sbin/ldconfig 

which is the list of commands I have so far executed in this instance of the terminal, which is verified by:

$ type ldconfig
ldconfig is hashed (/sbin/ldconfig)

Every time you execute a (non shell-builtin) command, it is automatically added to the 'cache' and lives there for the rest of the session- once you logout or even close the pseudo-terminal (like gnome-terminal) it is gone.

Another observation, the most recently executed command is added to the bottom of the list. I found this a good read: http://crashingdaily.wordpress.com/2008/04/21/hashing-the-executables-a-look-at-hash-and-type/

Comments:

Post a Comment:
Comments are closed for this entry.