Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

CentOS 版本信息查看全攻略:內核、發行版、架構一鍵獲取

編輯:關於 Linux

運維排障、軟件兼容性檢查、安全基線核查都需準確獲取 CentOS 版本信息。本文匯總 8 種查看命令,涵蓋內核版本、發行版號、32/64 位架構,附帶輸出解讀指南。

核心查看命令矩陣

需求推薦命令關鍵輸出字段
內核版本uname -r3.10.0-1160.el7.x86_64
完整內核信息uname -a內核名、主機名、版本、架構、時間
/proc 版本詳情cat /proc/versionGCC 版本、編譯時間、構建信息
發行版標識 (LSB)lsb_release -aDistributor ID、Description、Release、Codename
發行版簡潔版本cat /etc/redhat-releaseCentOS Linux release 7.9.2009 (Core)
issue 文件信息cat /etc/issue啟動顯示信息、內核佔位符
系統架構 (64/32位)getconf LONG_BIT64 或 32
二進制文件架構file /bin/lsELF 64-bit LSB executable, x86-64

實戰輸出解讀

示例 1:uname -a

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 支持、構建序號

示例 2: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
# 關鍵:Release 7.9.2009 = CentOS 7.9 (2009 年發布)

示例 3:cat /etc/redhat-release

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 為準
  • ✅ 內核版本決定模塊兼容性、安全補丁適用性

收藏本文,版本信息查詢不再東奔西走。

Copyright © Windows教程網 All Rights Reserved