Ubuntu16.04.4 The command could not be located

Ubuntu16.04.4 The command could not be located

修改过系统配置文件 /etc/environment  ,修改参数要是不正确,会导致所有命令失效错误,重启登陆系统的时候,就会显示如下的错误信息:

Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH envi                                                                                                                                                      ronment variable.
ls: command not found
Command 'lesspipe' is available in the following places
 * /bin/lesspipe
 * /usr/bin/lesspipe
The command could not be located because '/usr/bin:/bin' is not included in the                                                                                                                                                       PATH environment variable.
lesspipe: command not found
Command 'dircolors' is available in '/usr/bin/dircolors'
The command could not be located because '/usr/bin' is not included in the PATH                                                                                                                                                       environment variable.
dircolors: command not found
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH envi                                                                                                                                                      ronment variable.
ls: command not found


zslswrmz@ubuntu:~$

zslswrmz@ubuntu:~$ sudo
Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found


zslswrmz@ubuntu:~$ sudo su
Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found


zslswrmz@ubuntu:~$ ls -lh
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found


zslswrmz@ubuntu:~$
zslswrmz@ubuntu:~$

执行任何指令,都会报错,看到这样的错误,其实不用担心,那要如何解决呢?

之前修改过系统配置文件,肯定是配置有问题,意思是:找不到命令,因为 '/usr/bin:/bin' 没有被包含在环境变量PATH中, 这就是问题产生的原因。

Linux有PATH 通过PATH变量指定命令存放的位置, 所以正常情况下,使用 echo $PATH 查看环境变量PATH的内容如下:

~$ echo $PATH
/home/zslswrmz/bin:/home/scm/.local/bin:$JAVA_HOME/bin:$PATH
zslswrmz@ubuntu:~$

由于配置系统  PATH 错误,我在使用指令时系统不能正常到存放指令的目录中去寻找,因此会提示:Command not found。

很人性化的是,系统会提示我们要使用的指令存放的正确位置,比如使用 sudo 时提示的:Command 'sudo' is available in '/usr/bin/sudo'。sudo 命令是存放在'/usr/bin/'目录下的。

所以只能人工指定它们的绝对路径了。sudo 和 vim 都是存放在'/usr/bin/'目录下的,所以 sudo 和 vim 的绝对路径分别是:/usr/bin/sudo   /usr/bin/vim ,现在明白了吗?那就快快动手把之前修改错误的配置文件重新修改好,重启系统就OK了。

~$
zslswrmz@ubuntu:~$ /usr/bin/sudo /usr/bin/vim /etc/environment
[sudo] password for scm:
zslswrmz@ubuntu:~$
 

修改好重启系统,就能正常使用指令了,不会再报任何错了。

猜你喜欢

转载自my.oschina.net/sh021/blog/1789274