lin@lenovo:~$ su - root
口令:
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.
-su: mesg:找不到命令
root@lenovo:~# gedit /etc/profile
Command 'gedit' is available in '/usr/bin/gedit'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
-su: gedit:找不到命令
root@lenovo:~# useradd yul
Command 'useradd' is available in '/usr/sbin/useradd'
The command could not be located because '/usr/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative priviledges associated with your user account.
-su: useradd:找不到命令
root@lenovo:~# vi
Command 'vi' is available in '/usr/bin/vi'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
-su: vi:找不到命令
问题分析及解决办法:
这主要是路径问题,先查看$PATH变量的设置。
echo $PATH
里面的格式是xxx:xxx:xxx:xxx
这应该没包含/usr/bin这个路径。
执行下面命令就可以将这个路径包含进去:
export PATH=/usr/bin/:$PATH
如果要想每次登陆系统的时候,都自动包含这个路径,
可以把刚才这个命令加入到/root/.bash_profile或者/root/.bashrc文件的后面。
具体如下:
退回到普通用户(我的普通用户是lin)
lin@lenovo:~$ sudo gedit /root/.bash_profile
添加export PATH=/usr/bin/:$PATH,保存关闭.bash_profile文件
lin@lenovo:~$ su - root
口令:
root@lenovo:~# echo $PATH
/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@lenovo:~# env
SHELL=/bin/bash
TERM=xterm
XDG_SESSION_COOKIE=f591adb565a6ba1bc40f9e954a26895b-1255053756.679619-1536901825
USER=root
MAIL=/var/mail/root
PATH=/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/root
LANG=zh_CN.UTF-8
SHLVL=1
HOME=/root
LANGUAGE=zh_CN:zh
LOGNAME=root
_=/usr/bin/env
root@lenovo:~# vi
就可进行vi编辑了。