Linux command
rehash 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Rebuild the command hash table
rehash
Rehash after installing new software
sudo apt install [package] && rehash
说明
rehash is a shell builtin that rebuilds the internal hash table of executable commands. The shell maintains a hash table mapping command names to their full paths to avoid repeated $PATH searches. When new programs are installed or removed, this table can become outdated, causing the shell to report "command not found" for newly installed programs or to run stale paths. Running rehash forces the shell to discard the cached hash table and rediscover all executables in the directories listed in $PATH. In zsh, rehash also regenerates the completion list so that tab completion reflects newly installed commands.
FAQ
What is the rehash command used for?
rehash is a shell builtin that rebuilds the internal hash table of executable commands. The shell maintains a hash table mapping command names to their full paths to avoid repeated $PATH searches. When new programs are installed or removed, this table can become outdated, causing the shell to report "command not found" for newly installed programs or to run stale paths. Running rehash forces the shell to discard the cached hash table and rediscover all executables in the directories listed in $PATH. In zsh, rehash also regenerates the completion list so that tab completion reflects newly installed commands.
How do I run a basic rehash example?
Run `rehash` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
Where can I find more rehash examples?
This page includes 2 examples for rehash, plus related commands for nearby Linux tasks.