为什么 Linux 不在 PATH 环境的所有目录中寻找命令?

Why doesn't Linux seek the command in all the directories in PATH environment?

我首先通过 docker site 中的以下命令安装 docker:

curl -s -O https://get.docker.com/builds/Linux/x86_64/docker-1.6.1 && chmod +x docker-1.6.1 && sudo mv docker-1.6.1 /usr/local/bin/docker

然后我删除 /usr/local/bin 目录中的 docker

我再次通过yum安装docker,这次docker安装在/usr/bin目录:

[root@dl380gen8snbjbb ~]# ls -lt /usr/bin/docker
-rwxr-xr-x 1 root root 13451927 Apr 20 13:44 /usr/bin/docker

当我在命令中执行docker时:

[root@dl380gen8snbjbb ~]# docker
-bash: /usr/local/bin/docker: No such file or directory

/usr/bin 实际上在 PATH 中:

[root@dl380gen8snbjbb ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

为什么系统不在/usr/bin目录中寻找docker命令?

检查以下内容 link: https://unix.stackexchange.com/q/5609/55635

bash does cache the full path to a command. You can verify that the command you are trying to execute is hashed with the type command:

$ type svnsync svnsync is hashed (/usr/local/bin/svnsync)

To clear the entire cache:

$ hash -r

Or just one entry:

$ hash -d svnsync

For additional information, consult help hash and man bash.