yingfeng
心明若鏡,不將不迎

Debian 安装完成找不到命令解决方法

之前做测试的时候在起了一个Debian的虚拟机,结果系统安装完成发现问题很多,系统就连最基础的service、reboot、poweroff 等命令都无法使用,让我一度怀疑是我系统没装好,甚至还重新安装了一遍,结果还是找不到命令,彻底懵逼

其实造成这个问题的原因是没有把 /sbin 的目录路径(系统用户目录)添加到$PATH变量中

#查看当前$PATH
root@debian:/home/user# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

如果没有 /sbin 可以使用以下命令

root@debian:/home/user# export PATH=$PATH:/sbin/
root@debian:/home/user#

临时把对应路劲加到$PATH变量中,测试一下是否可用。
但是这只是临时添加,断开ssh重连就失效了,需要永久添加需要编辑 .bashrc 文件(每个用户都有.bashrc 文件,想要每个用户都能正常使用,需要去编辑每个用户的 .bashrc 文件)

#切换到root目录
root@debian:/home/user# cd ~
root@debian:~# 
#编辑文件
root@debian:~# vim .bashrc

在最后一行添加

export PATH=$PATH:/usr/sbin
# ~/.bashrc: executed by bash(1) for non-login shells. 
 
# Note: PS1 and umask are already set in /etc/profile. You should not 
# need this unless you want different defaults for root. 
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ ' 
# umask 022 
 
# You may uncomment the following lines if you want `ls' to be colorized: 
# export LS_OPTIONS='--color=auto' 
# eval "`dircolors`" 
# alias ls='ls $LS_OPTIONS' 
# alias ll='ls $LS_OPTIONS -l' 
# alias l='ls $LS_OPTIONS -lA' 
# 
# Some more alias to avoid making mistakes: 
# alias rm='rm -i' 
# alias cp='cp -i' 
# alias mv='mv -i' 
export PATH=$PATH:/usr/sbin

保存后,执行一下

root@debian:~# source ~/.bashrc
root@debian:~#

然后在重新查看一下$PATH变量

root@debian:~# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin

可以看到,多了个/usr/sbin

现在就可以正常的使用reboot、service等命令了。

本文发布于:yingfeng Blog>>Debian 安装完成找不到命令解决方法,转载请注明出处。

评论 5

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    感谢分享

    跨境电商6个月前 (09-27)回复
  2. #0

    谢谢大神,我刚装完打印机驱动,就用不了,按你这操作可以了,谢谢

    frigo2年前 (2022-04-09)回复
  3. #0

    哪里来的debian会这么残废的,我一般只在docker hub上会碰到一些像这样的精简的镜像,说明也不全。

    yfresh2年前 (2021-10-28)回复