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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 提示-bash: command not found的解决方法集锦

错误原因


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


  1. 你将命令的名称拼错了。
  2. 该命令还没有安装。
  3. 该命令是一个可执行脚本,但其位置未知。




解决方案


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


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


   find / -name profile #找到该文件(这个文件相当于 你在Windows 中加入环境变量那块),一般该文件在 /etc/profile 这里

   vim profile #编辑该文件

   export PATH="$PATH:/phpstudy/mysql/bin" #在该文件中加入 command not found 的应用 bin 目录,这里我是将 mysql 的 bin 放到这里,因为我是 mysqld / mysqldump / mysqladmin 命令用不了


   source /etc/profile // 更新配置(不用重启系统)

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


   -bash: rz: 未找到命令

   yum install lrzsz


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


yum list telnet*                  列出telnet相关的安装包
yum install telnet-server         安装telnet服务
yum install telnet.*              安装telnet客户端


   -bash: wget: command not found

   yum install wget -y

Debian/Ubuntu系统,需要执行以下命令:


apt-get install -y wget
    -bash: unzip: command not found
    yum install unzip
    -bash: ntpdate: command not found
    yum install ntpdate
    -bash: nmap: command not found
    yum install nmap
    -bash: lsof: command not found
    yum install lsof -y
    -bash: fuser: command not found
    yum install psmisc
    -bash: yum-config-manager: command not found
    yum -y install yum-utils
    -bash: psql: command not found
    yum install postgresql 或者 yum install postgresql-server
    ifconfig: command not found
    yum install -y net-tools
    -bash: netstat: command not found
    yum install -y net-tools
    firewall-cmd: command not found
    yum install firewalld -y
    multipath: command not found
    yum install device-mapper-multipath
    ip: command not found (CentOS Linux release 7.8.2003 (Core) )
    yum install initscripts
    autoreconf: command not found
    yum install install autoconf -y
    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
    yum-builddep: command not found
    yum install yum-utils -y
    rpmbuild: command not found
    yum install rpm-build -y
    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
• 1
• 2


3)永久关闭防火墙

systemctl disable firewalld
 chkconfig iptables off


4)重启防火墙

systemctl enable firewalld
 service iptables restart  
• 1
• 2


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

chkconfig iptables on

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7月前
|
关系型数据库 MySQL Shell
【Linux命令】-bash: mysql: command not found
【Linux命令】-bash: mysql: command not found
60 0
|
6天前
|
Shell Linux
重装yum |-bash: yum: command not found
重装yum |-bash: yum: command not found
32 0
|
6天前
|
Linux Shell
mac/linux提示bash: telnet: command not found
mac/linux提示bash: telnet: command not found
|
6天前
|
Shell 应用服务中间件 开发工具
bash: vi: command not found
bash: vi: command not found
|
6天前
|
监控 安全 Shell
防止员工泄密的措施:在Linux环境下使用Bash脚本实现日志监控
在Linux环境下,为防止员工泄密,本文提出使用Bash脚本进行日志监控。脚本会定期检查系统日志文件,搜索敏感关键词(如"password"、"confidential"、"secret"),并将匹配项记录到临时日志文件。当检测到可疑活动时,脚本通过curl自动将数据POST到公司内部网站进行分析处理,增强信息安全防护。
121 0
|
6天前
|
Linux Shell Windows
4:Bash shell命令-步入Linux的现代方法
4:Bash shell命令-步入Linux的现代方法
55 0
|
9月前
|
Ubuntu 安全 Linux
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
161 0
|
6天前
|
存储 Shell Linux
Linux Bash 脚本中的 IFS 是什么?
【4月更文挑战第25天】
30 0
Linux Bash 脚本中的 IFS 是什么?
|
6天前
|
Shell Linux
【Linux】Bash支持各种指令选项的原理:命令行参数
【Linux】Bash支持各种指令选项的原理:命令行参数
|
6天前
|
Java Shell Linux
【linux进程控制(三)】进程程序替换--如何自己实现一个bash解释器?
【linux进程控制(三)】进程程序替换--如何自己实现一个bash解释器?