查看CentOS版本方法
封面图
•
2025-11-04
•
Linux
288
1
1
0
查看 CentOS 版本的方法有多种,以下是常用的几种方式: --- ### ✅ 方法 1:使用 `cat` 命令查看 `/etc/os-release` 文件 ```bash cat /etc/os-release ``` 输出示例: ``` NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MIRROR="http://mirror.centos.org/centos/$releasever/os/$basearch/" ``` - `VERSION` 行显示的是 CentOS 的版本号(如 7、8、9)。 --- ### ✅ 方法 2:查看 `/etc/redhat-release` 文件(适用于 CentOS) ```bash cat /etc/redhat-release ``` 输出示例: ``` CentOS Linux release 7.9.2009 ``` --- ### ✅ 方法 3:使用 `hostnamectl` 命令(适用于较新的系统) ```bash hostnamectl ``` 输出示例: ``` Operating System: CentOS Linux 7 (Core) Kernel Version: 3.10.0-1160.el7.x86_64 Architecture: x86-64 ``` --- ### ✅ 方法 4:使用 `rpm` 命令查询 centos-release 包 ```bash rpm -q centos-release ``` 输出示例: ``` centos-release-7-9.2009.el7.centos.x86_64 ``` - 这里的 `7` 表示 CentOS 7,`8` 表示 CentOS 8 等。 --- ### ✅ 方法 5:使用 `lsb_release` 命令(如果安装了该工具) ```bash lsb_release -a ``` 输出示例: ``` LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.9.2009 Release: 7.9.2009 Codename: Core ``` --- ### ✅ 方法 6:查看 `/etc/centos-release` 文件(适用于 CentOS) ```bash cat /etc/centos-release ``` 输出示例: ``` CentOS Linux release 7.9.2009 ``` --- ### 总结 | 方法 | 适用系统 | 说明 | |------|----------|------| | `cat /etc/os-release` | 所有 CentOS 7+ | 推荐使用 | | `cat /etc/redhat-release` | CentOS 7+ | 旧方法 | | `hostnamectl` | CentOS 7+ | 查看系统信息 | | `rpm -q centos-release` | CentOS 7+ | 通过包名判断版本 | | `lsb_release -a` | CentOS 7+ | 需要安装 `redhat-lsb` 包 | | `cat /etc/centos-release` | CentOS 7+ | 仅适用于 CentOS | --- 如果你告诉我你使用的 CentOS 版本(比如是 7、8、9 或 10),我可以提供更具体的帮助。
上一篇:
CentOS 5.4 防火墙配置80端口的方法(适用于centos5.3以上版本)
下一篇:
Centos中压缩(zip)和解压(unzip)命令
标题录入,一次不能超过6条
留言
评论