LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

hash

shell built-in that manages the hash table of recently executed commands

TLDR

Show command hash table
$ hash
copy
Clear hash table
$ hash -r
copy
Add command to hash
$ hash -p [/usr/local/bin/mycommand] [mycommand]
copy
Remove command from hash
$ hash -d [command]
copy
Show path for command
$ hash -t [command]
copy

SYNOPSIS

hash [options] [name...]

DESCRIPTION

hash is a shell built-in that manages the hash table of recently executed commands. The shell uses this table to remember the full paths of commands, avoiding repeated PATH searches.When a command is executed, the shell stores its path in the hash table. Subsequent invocations use the cached path, improving performance.

$ # View hash table
hash

# Clear after installing new software
hash -r

# Check where a command is hashed
hash -t python

# List all hashed commands
hash -l
copy

PARAMETERS

-r

Clear hash table.
-p path name
Add path for name.
-d name
Delete name from hash.
-t name
Print path for name.
-l
List in reusable format.

CAVEATS

Shell built-in; behavior and available options vary by shell (bash, zsh, ksh each implement their own version). The hash table becomes stale if a hashed command's file is moved or removed. Run `hash -r` after installing software or modifying PATH. Only affects the current shell session, not child processes.

HISTORY

hash has been part of Unix shells since the Bourne shell. POSIX only mandates the `-r` option; bash extends it with `-p`, `-d`, `-t`, and `-l` for finer control over the command path cache.

SEE ALSO

type(1), which(1), whence(1), command(1)

RESOURCES

Copied to clipboard
Kai