運維排障、軟件兼容性檢查、安全基線核查都需準確獲取 CentOS 版本信息。本文匯總 8 種查看命令,涵蓋內核版本、發行版號、32/64 位架構,附帶輸出解讀指南。
| 需求 | 推薦命令 | 關鍵輸出字段 |
|---|---|---|
| 內核版本 | uname -r | 3.10.0-1160.el7.x86_64 |
| 完整內核信息 | uname -a | 內核名、主機名、版本、架構、時間 |
| /proc 版本詳情 | cat /proc/version | GCC 版本、編譯時間、構建信息 |
| 發行版標識 (LSB) | lsb_release -a | Distributor ID、Description、Release、Codename |
| 發行版簡潔版本 | cat /etc/redhat-release | CentOS Linux release 7.9.2009 (Core) |
| issue 文件信息 | cat /etc/issue | 啟動顯示信息、內核佔位符 |
| 系統架構 (64/32位) | getconf LONG_BIT | 64 或 32 |
| 二進制文件架構 | file /bin/ls | ELF 64-bit LSB executable, x86-64 |
Linux localhost.localdomain 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.10.0-1160.el7.x86_64 → 內核版本(主版本.次版本.修訂-構建號.發行版.架構)
# x86_64 → 64位架構(i686/i386 為 32位)
# #1 SMP → SMP 支持、構建序號
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
# 關鍵:Release 7.9.2009 = CentOS 7.9 (2009 年發布)
CentOS Linux release 7.9.2009 (Core)
# 通用於 RHEL/CentOS/Fedora/Oracle Linux 等紅帽系
#!/bin/bash
# get_os_info.sh
echo "=== Kernel ===" && uname -r
echo "=== Architecture ===" && getconf LONG_BIT
echo "=== Distribution ==="
if command -v lsb_release &>/dev/null; then
lsb_release -d | cut -f2
else
cat /etc/redhat-release 2>/dev/null || cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d'"' -f2
fi
echo "=== Full Kernel ===" && uname -a
# 現代系統 (systemd)
cat /etc/os-release
# NAME="CentOS Linux"
# VERSION="7 (Core)"
# VERSION_ID="7.9.2009"
# 容器環境
hostnamectl
# Operating System: CentOS Linux 7 (Core)
# Kernel: Linux 3.10.0-1160.el7.x86_64
# Architecture: x86-64
/etc/issue 可被自定義修改,不可作為權威來源uname -r 僅反映內核,不代表用戶空間工具版本/etc/os-release + lsb_release 為準收藏本文,版本信息查詢不再東奔西走。