Home / Posts

Hash Fast, Bash Smart

tech bash

(Published: 2024-10-14)

Hash Fast, Bash Smart

hash is a useful built-in shell command used for caching commands/executables from your $PATH variable. This helps bash/zsh avoid having to rescan your PATH each time you enter a command during the find and execution process.

This command is great for resetting/regenerating the PATH commands cache with the -r flag. For example, python3’s virtualenv uses this to manage your command cache after activating and deactivating your virtual environment.

hash -r 2> /dev/null

This snippet runs hash with -r flag to “reset” the commands cache. Error/logging is discarded to /dev/null for quiet execution.

Note: Running hash alone just prints out the current command cache list

Use Cases

To learn a bit more about hash, check out the bash manual entry.