centos 通用查看系统版本信息
查看centos6/7系统版本
要写一个centos系统的初始化脚本,但是centos6和centos7版本有很多命令都不相同,所以为了让脚本在两个版本之间都可以使用,就需要对centos系统版本进行判断。
通过查找各种资料,我发现基本有下面几种查看系统版本的方法:
#### 方法一:
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
方法二:
cat /etc/os-release
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
[root@9952acf06e8c opt]# 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"
** 但是,centos6里没有这个文件,所以这个方法也不适用。
** #### 方法三:
cat /etc/redhat-release(/etc/centos-release)
CentOS Linux release 7.7.1908 (Core)
#### 方法四:
rpm -q centos-release
centos-release-7-7.1908.0.el7.centos.x86_64
添加新评论