...making Linux just a little more fun!

2-Cent Tips

2-cent Tip: Caching in the Shell

Amit k. Saha [amitsaha.in at gmail.com]


Wed, 16 Jul 2008 15:04:37 +0530

Hi Gang,

Just wanted to share this with you: (I am sure most of you already know this)

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

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.

Happy to share!

I found this a good read: https://crashingdaily.wordpress.com/2008/04/21/hashing-the-executables-a-look-at-hash-and-type/

-Amit

-- 
Amit Kumar Saha
https://blogs.sun.com/amitsaha/
https://amitksaha.blogspot.com
Skype: amitkumarsaha



Talkback: Discuss this article with The Answer Gang

Copyright © 2008, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 153 of Linux Gazette, August 2008

Tux