CentOS6和7怎样查看版本

本文将介绍Centos6和7中怎样查看系统版本信息。

要写一个CentOS系统的初始化脚本,但是CentOS6和CentOS7版本有很多命令都不相同,所以为了让脚本在两个版本之间都可以使用,就需要对centos系统版本进行判断。

CentOS6

/etc/redhat-release

使用cat查看该文件,该文件保存了版本信息。如下:

[root@S0 ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)

/etc/centos-release

使用cat查看该文件,该文件保存了版本信息。如下:

[root@S0 ~]# cat /etc/centos-release
CentOS release 6.4 (Final)

rpm -q centos-release

使用 centos-relase 命令查看,如下:

[root@S0 ~]# rpm -q centos-release
centos-release-6-4.el6.centos.10.i686

CentOS7

cat /etc/os-release

可以使用cat直接查看 /etc/os-release 文件。如下:

[root@S5 ~]# 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"

/etc/redhat-release

使用cat查看该文件,该文件保存了版本信息。如下:

[root@S5 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

cat /etc/centos-release

使用cat查看该文件,该文件保存了版本信息。如下:

[root@S5 ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

rpm -q centos-release

使用 centos-release查看,如下:

[root@S5 ~]# rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64
学习必须与实干相结合。 —— 泰戈尔
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号