无法找到该命令,因为’/ sbin’未包含在PATH环境变量中

我今天遇到了严重的问题:当我输入ifconfig它不会在ubuntu 12.04上显示ip配置。 谁可以帮我这个事?

这是ifconfig的结果:

 Command 'ifconfig' is available in '/sbin/ifconfig' The command could not be located because '/sbin' is not included in the PATH environment variable. This is most likely caused by the lack of administrative privileges associated with your user account. ifconfig: command not found 

试试这个命令:

 sudo ln -s /sbin/ifconfig /usr/bin/ifconfig 

您可以执行以下任一操作:

  • 打开~/.bashrc文件并将以下内容写到最后:

     export PATH=$PATH:/sbin 

然后执行source ~/.bashrc或打开一个新的终端实例。

  • 或者打开/etc/environment并将/sbin添加到PATH变量的末尾,如下所示:

     PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/usr/games:/sbin" 

通过运行将/sbin添加到系统路径,

 export PATH=$PATH:/sbin 

如果你按照@nux的答案,你必须为/sbin目录中显示的所有命令文件创建符号链接。但是如果你按照这个或@ jobin的答案,你不需要那样做。

如果要在系统范围内永久地将/sbin添加到PATH ,您应该:

  1. /etc/profile.d创建新的可执行文件;
  2. export PATH=$PATH:/sbin写入创建的文件中;
  3. 运行source /etc/profile

现在无论是重新启动还是更改用户,都可以正确获取PATH