查看Linux发行版名称和版本号

最常用的查看Linux发行版信息的命令

  • Ubuntu
    	[root@a8ec86acc075 /]# lsb_release -a
    	No LSB modules are available.
    	Distributor ID:	Ubuntu
    	Description:	Ubuntu 18.04.4 LTS
    	Release:	18.04
    	Codename:	bionic
    	[root@a8ec86acc075 /]# cat /etc/lsb-release 
    	DISTRIB_ID=Ubuntu
    	DISTRIB_RELEASE=18.04
    	DISTRIB_CODENAME=bionic
    	DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
    
  • CentOS
    	# 第一种
    	[root@a8ec86acc075 /]# cat /etc/os-release 
    	NAME="CentOS Linux"
    	VERSION="8 (Core)"
    	ID="centos"
    	ID_LIKE="rhel fedora"
    	VERSION_ID="8"
    	PLATFORM_ID="platform:el8"
    	PRETTY_NAME="CentOS Linux 8 (Core)"
    	ANSI_COLOR="0;31"
    	CPE_NAME="cpe:/o:centos:centos:8"
    	HOME_URL="https://www.centos.org/"
    	BUG_REPORT_URL="https://bugs.centos.org/"
    
    	CENTOS_MANTISBT_PROJECT="CentOS-8"
    	CENTOS_MANTISBT_PROJECT_VERSION="8"
    	REDHAT_SUPPORT_PRODUCT="centos"
    	REDHAT_SUPPORT_PRODUCT_VERSION="8"
    	# 第二种
    	[root@a8ec86acc075 /]# cat /etc/redhat-release
    	CentOS Linux release 8.2.2004 (Core)
    

lsb_release -a

LSB(Linux 标准库Linux Standard Base)能够打印发行版的具体信息,包括发行版名称、版本号、代号等。

示例CentOS

[root@aliyun ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.7.1908 (Core)
Release:	7.7.1908
Codename:	Core

示例Ubuntu

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic

/etc/*-release 文件

release文件通常被视为操作系统的标识。在/etc目录下放置了很多记录着发行版各种信息的文件,每个发行版都各自有一套这样记录着相关信息的文件。

示例CentOS

[root@aliyun ~]# 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_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

示例Ubuntu

➜  ~ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
➜  ~ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic