linux系统所有命令突然用不了的解决方法

错误:

dircolors: command not found
Command mesg is available in /usr/bin/mesg
The command could not be located because /usr/bin is not included in the PATH environment variable.
mesg: command not found
root@itcast:~# docker ps
Command docker is available in /usr/bin/docker
The command could not be located because /usr/bin is not included in the PATH environment variable.
docker: command not found
root@itcast:~# ls
Command ls is available in /usr/bin/docker
The command could not be located because /usr/bin is not included in the PATH environment variable.
ls: command not found

原因分析:

在配置/etc/profile文件时,将此文件中的路径破坏了。即下面这个路径 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

解决办法:

先用vi /etc/profile(这个命令可用)命令打开配置文件,检查你的配置环境变量时的路径是否写正确,如 检查配置路径没问题之后,如果命令还是无法使用,再尝试下面的方法 注意:还有一种情况是所有命令无法使用的,就是你误删了系统文件,导致系统瘫痪,我之前就是过误删了系统的一些文件,结果完全登录不了系统,这种情况你只能考虑重装系统

以下使用的命令均在普通模式下。

第一步:查看path中是否含有/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

使用以下命令(目的是查看path中是否含有/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin),应该是没有的。

echo $PATH

这是我的结果

第二步:使用临时变量(此临时变量在客户机重新启动后消失),手动加载环境路径

使用以下命令:

 export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin      

第三步:修改永久变量,对环境变量进行配置。

1.修改profile文件,对于所有的用户均需要修改 (1) 使用以下命令 vi /etc/profile 然后在文件的最后加入下列路径: export PATH=$PATH: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin         或者 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib   (2)使用:wq命令保存退出 如果在使用:wq命令如果不能保存退出,在开始使用vi /etc/profile命令时,前面加上sudo,即就是: sudo vi /etc/profile 2.修改.bashrc文件,对于单独的用户需要修改的(这一步我不需要修改,因为我的不是单用户) (1) 使用命令vi /~/.bashrc (‘~’代表的是家目录)回车。然后在文件的最后面加入 export PATH=$PATH: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin (2)使用:wq命令保存退出 3.重新启动虚拟机就可恢复所有的root命令(最好重启一下)
经验分享 程序员 微信小程序 职场和发展