在阿里云服务器上用什么命令查看CentOS或Ubuntu版本?

在阿里云服务器上查看 CentOS 或 Ubuntu 版本,可以使用以下命令:

通用方法(适用于大多数 Linux 发行版)

1. 查看发行版信息

cat /etc/os-release

这个命令会显示详细的发行版信息,包括名称、版本号、ID等。

2. 查看内核版本

uname -r

显示当前运行的内核版本。

CentOS/RHEL 系统专用命令

1. 查看 CentOS 版本

cat /etc/centos-release

cat /etc/redhat-release

2. 使用 rpm 查询

rpm -q centos-release

Ubuntu/Debian 系统专用命令

1. 查看 Ubuntu 版本

lsb_release -a

显示包括发行版ID、描述、版本号、代号等完整信息。

2. 查看版本文件

cat /etc/lsb-release

cat /etc/issue

快速判断系统类型

如果不确定当前是 CentOS 还是 Ubuntu,可以先运行:

cat /etc/os-release | grep "^NAME="

hostnamectl

示例输出

CentOS 示例:

$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

Ubuntu 示例:

$ lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

推荐使用

对于阿里云服务器,最可靠的方法是使用:

cat /etc/os-release

这个命令在所有主流 Linux 发行版上都可用,并且提供最完整的信息。

云服务器