如何查看自己linux的版本号

在 Linux 系统中,可以通过以下命令查看系统版本信息(适用于 CentOS/RHEL、Ubuntu/Debian、Arch、Fedora 等主流发行版):

1. 查看 Linux 发行版(Distribution)信息

(1)使用 lsb_release(通用方法)

lsb_release -a

输出示例:

LSB Version: :core-4.1-amd64:core-4.1-noarch

Distributor ID: CentOS

Description: CentOS Linux release 7.9.2009 (Core)

Release: 7.9.2009

Codename: Core

如果提示 lsb_release: command not found,先安装:

CentOS/RHEL: sudo yum install redhat-lsb-coreUbuntu/Debian: sudo apt install lsb-release

(2)查看 /etc/os-release 文件

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)"

2. 查看内核版本(Kernel Version)

uname -r

输出示例:

3.10.0-1160.el7.x86_64

说明:

3.10.0 是内核版本号el7 表示适用于 RHEL/CentOS 7

查看完整内核信息

uname -a

输出示例:

Linux myhost 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

3. 针对特定发行版的命令

CentOS/RHEL

cat /etc/centos-release # CentOS 专用

cat /etc/redhat-release # RHEL 专用

输出示例:

CentOS Linux release 7.9.2009 (Core)

Ubuntu/Debian

cat /etc/issue

输出示例:

Ubuntu 20.04.4 LTS \n \l

4. 查看系统架构(32/64位)

arch

uname -m

输出示例:

x86_64 # 64位系统

i386 # 32位系统

总结表

需求命令发行版名称/版本lsb_release -a、cat /etc/os-release内核版本uname -r、uname -aCentOS/RHEL 版本cat /etc/centos-release、cat /etc/redhat-releaseUbuntu/Debian 版本cat /etc/issue系统架构arch、uname -m

根据你的需求选择对应命令即可快速获取系统信息!