歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu中root用戶沒有辦法使用命令

Ubuntu中root用戶沒有辦法使用命令

日期:2017/2/28 16:42:30   编辑:Linux教程

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編輯了。

Copyright © Linux教程網 All Rights Reserved