【问题标题】:Cannot find a executable file after I move it to another folder in $PATH将可执行文件移动到 $PATH 中的另一个文件夹后找不到可执行文件
【发布时间】:2015-04-18 14:56:23
【问题描述】:

Linux 上的一个小实验。

root@ubuntu:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
root@ubuntu:/# which ls
/bin/ls
root@ubuntu:/# mv /bin/ls /root
root@ubuntu:/# ls
bash: /bin/ls: No such file or directory
root@ubuntu:/# export PATH=$PATH:/root
root@ubuntu:/# ls
bin  boot  cdrom  dev  etc  home ...
root@ubuntu:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root
root@ubuntu:/# mv /root/ls /bin/
root@ubuntu:/# ls
bash: /root/ls: No such file or directory

我只是将 /bin/ls 移动到 /root,然后将 /root 添加到 $PATH,现在 ls 是可执行的。

当我再次将 /root/ls 移动到 /bin/ 时,'ls' 无法执行,系统只是找不到文件 'ls'。那么问题出在哪里?

【问题讨论】:

    标签: linux environment-variables


    【解决方案1】:

    删除可执行文件的 bash 缓存路径。

    hash -d ls
    

    【讨论】:

    • 是否可以禁用 bash 的缓存?
    猜你喜欢
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 2019-01-16
    • 2015-01-25
    • 2015-05-19
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多