LinuxCommandLibrary

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 varies by shell. Hash becomes stale if commands move. Use hash -r after PATH changes or software installation. Only affects current shell session.

HISTORY

The hash command has been part of Unix shells since the Bourne shell. It provides manual control over the command path caching mechanism that shells use for performance.

SEE ALSO

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

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard