https://rumenz.com/rumenbiji/centos-check-version.html
那么怎么知道我们线上正在跑的是哪个版本呢?
现在CentOS Linux有4个主要的发布分支,CentOS 5,CentOS 6CentOS 7和CentOS 8
lsb_release命令显示有关Linux发行版的Linux Standard Base(LSB)信息。这是首选方法,无论你运行的是哪种CentOS版本都应该可以使用。
打开终端并键入以下命令:
lsb_release -a

CentOS版本将显示在”description”行中。从上面的输出可以看出我使用的是CentOS Linux 7.5.1804版。
这些版本号的数字
7.5.1804都指的是什么
7 是CentOS的主要分支7.5 是CentOS 7的最新次要版本1804 是次要版本的日期代码,1804表示2018年4月,数字用于指示发布的时间如果你在执行命令时看到
bash: lsb_release: command not found...,则表示redhat-lsb-core没有在你的系统上未安装该软件包。你可以使用以下方法安装该软件
sudo yum install redhat-lsb-core
rpm(Red Hat Package Manager)是基于Red Hat的系统(如RHEL,CentOS和Fedora)的软件包管理工具。你可以使用rpm工具显示有关
centos-release包的信息,其中包括名称中的CentOS版本
rpm --query centos-releasecentos-release-7-18elcentos.x86_64
/etc/centos-release文件由centos-release包提供。要检查CentOS版本,请输入以下命令:
cat /etc/centos-releaseCentOS Linux release 1804 (Core)/etc/os-release文件检查CentOS版本
/etc/os-release文件存在于运行systemd的所有系统上,并包含操作系统标识数据。只有拥有CentOS 7时,此方法才有效
> cat /etc/os-releaseNAME="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="hostnamectl命令检查你的CentOS版本
hostnamectl是一个允许你设置主机名的命令,但你也可以使用它来查找你的CentOS版本只有在CentOS 7时,此方法才有效
> hostnamectlStatic hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: 2849f743fbe74706abaa6cb8b2ae5377 Boot ID: 8259a43c6265465884920ac6d762ed5e Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 0-8elx86_64 Architecture: x86-64【Linux常用命令速查手册】关注【入门小站】,后台回复 「1001」 自取。