提示-bash: command not found的解决方法集锦

错误原因

  最近很多小伙伴私信我说老是遇到命令找不到的情况,这里开一篇插个队说一下这个问题,做个总结。当我们在 Linux(或shell)下执行一个命令时,报 -bash: XXXX: command not found,有三个可能的原因:

  1. 你将命令的名称拼错了。

  2. 该命令还没有安装。

  3. 该命令是一个可执行脚本,但其位置未知。

解决方案

第一个很简单,仔细排查一下,命令或者文件名之类的写错了没有。

第三个这和Windows是相同的道理,都是环境变量惹的祸,就是说你的 命令的 执行文件不在 /usr/bin 或者 /etc/init.d 中,他就找不到 执行该命令的 文件来执行。思路是将该应用的 bin 目录 放入到 profile 文件中就OK了,步骤如下:

  1. find / -name profile #找到该文件(这个文件相当于 你在Windows 中加入环境变量那块),一般该文件在 /etc/profile 这里
  2. vim profile #编辑该文件
  3. export PATH="$PATH:/phpstudy/mysql/bin" #在该文件中加入 command not found 的应用 bin 目录,这里我是将 mysql 的 bin 放到这里,因为我是 mysqld / mysqldump / mysqladmin 命令用不了
  4. source /etc/profile // 更新配置(不用重启系统)

这还不行那就是第二个原因了,那就是没有安装这个插件了,解决办法如下:

  1. -bash: rz: 未找到命令
    yum install lrzsz

  2. 提示-bash: telnet: command not found的解决方法

yum list telnet*                  列出telnet相关的安装包
yum install telnet-server         安装telnet服务
yum install telnet.*              安装telnet客户端
  1. -bash: wget: command not found
    yum install wget -y

Debian/Ubuntu系统,需要执行以下命令:
apt-get install -y wget

  1. -bash: unzip: command not found
    yum install unzip

  2. -bash: ntpdate: command not found
    yum install ntpdate

  3. -bash: nmap: command not found
    yum install nmap

  4. -bash: lsof: command not found
    yum install lsof -y

  5. -bash: fuser: command not found
    yum install psmisc

  6. -bash: yum-config-manager: command not found
    yum -y install yum-utils

  7. -bash: psql: command not found
    yum install postgresql 或者 yum install postgresql-server

  8. ifconfig: command not found
    yum install -y net-tools

  9. -bash: netstat: command not found
    yum install -y net-tools

  10. firewall-cmd: command not found
    yum install firewalld -y

  11. multipath: command not found
    yum install device-mapper-multipath

  12. ip: command not found (CentOS Linux release 7.8.2003 (Core) )
    yum install initscripts

  13. autoreconf: command not found
    yum install install autoconf -y

  14. autoreconf: failed to run autopoint: No such file or directory err:
    autoreconf: running: autopoint --force
    Can’t exec “autopoint”: No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 345.
    autoreconf: failed to run autopoint: No such file or directory
    autoreconf: autopoint is needed because this package uses Gettext fixed:
    yum install -y gettext-devel

  15. yum-builddep: command not found
    yum install yum-utils -y

  16. rpmbuild: command not found
    yum install rpm-build -y

  17. Redirecting to /bin/systemctl stop iptables.service
    Failed to stop iptables.service: Unit iptables.service not loaded.
    yum install iptables-services
    实际上,centos7后是使用的基于iptable的

systemctl stop firewalld
systemctl mask firewalld

设置开机启动:

systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
systemctl enable iptables

保存设置:
service iptables save

1)查看防火状态

    systemctl status firewalld
    service  iptables status

2)暂时关闭防火墙

    systemctl stop firewalld
    service  iptables stop

3)永久关闭防火墙

 systemctl disable firewalld
 chkconfig iptables off

4)重启防火墙

 systemctl enable firewalld
 service iptables restart  

5)永久关闭后重启(未测试)
chkconfig iptables on

转载自:https://blog.youkuaiyun.com/u014727709/article/details/130915064
欢迎start,欢迎评论,欢迎指正

### Xshell 中 `-bash: command not found` 的解决方案 当在 Xshell 连接到 Linux 系统时遇到 `-bash: command not found` 错误,通常是因为环境变量 `PATH` 配置不正确或者某些工具未安装。以下是详细的分析和解决方法: #### 1. 检查并修复环境变量 `PATH` 如果只有少数几个命令可用(如 `cd`),而其他常用命令不可用,则可能是环境变量 `PATH` 被错误配置或丢失。可以通过以下方式临时设置 `PATH` 来恢复基本功能: ```bash export PATH=/bin:/usr/bin:$PATH ``` 此操作会将 `/bin` 和 `/usr/bin` 添加到当前用户的路径中[^2]。 为了永久修改 `PATH`,可以编辑 `.bashrc` 或 `.profile` 文件,在其中添加类似的路径定义: ```bash echo 'export PATH=/bin:/usr/bin:$PATH' >> ~/.bashrc source ~/.bashrc ``` #### 2. 安装缺失的软件包 如果确认某些特定命令确实不存在于系统中,可能需要重新安装对应的工具。例如: - **Vim 编辑器** 如果运行 `vim` 报错 `-bash: vim: command not found`,则说明 Vim 尚未安装。可通过以下命令安装: ```bash yum -y install vim* ``` 此命令会自动下载并安装 Vim 及其依赖项[^3]。 - **Wget 工具** 对于 `-bash: wget: command not found` 错误,可按照以下步骤处理: 1. 卸载现有的 Wget(如果有问题版本): ```bash yum remove wget ``` 2. 清除 YUM 缓存以避免潜在冲突: ```bash rm -rf /var/cache/yum/* yum clean all ``` 3. 列出可用仓库以验证网络连接正常: ```bash yum repolist ``` 4. 重新安装 Wget: ```bash yum -y install wget ``` #### 3. 排查更深层次的原因 如果上述两种情况均无法解决问题,建议进一步排查是否存在以下原因: - 用户权限不足:切换至超级用户模式后再测试命令是否有效。 - Shell 类型异常:通过 `echo $SHELL` 查看当前使用的 shell 是否为 Bash。如果不是,请手动指定使用 Bash: ```bash bash ``` - 系统文件损坏:尝试重启服务器或将有问题的服务容器销毁重建。 --- ### 总结 对于 Xshell 中出现的 `-bash: command not found` 问题,优先检查环境变量 `PATH` 设置是否正确;其次判断是否有必要工具尚未安装,并利用包管理器完成安装过程。最后考虑是否存在底层系统层面的问题。
评论 29
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想你依然心痛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值