There are many ways to check the CentOS version. In this tutorial, we will learn how to check the CentOS version through eight different utilities.

有很多方法可以检查CentOS版本。 在本教程中,我们将学习如何通过八个不同的实用程序来检查CentOS版本。

检查CentOS版本的8种方法 (8 Ways to Check CentOS Version)

  1. /etc/centos-release file/ etc / centos-release文件
  2. /etc/system-release file/ etc / system-release文件
  3. /etc/os-release file/ etc / os-release文件
  4. /etc/redhat-release file/ etc / redhat-release文件
  5. lsb_release commandlsb_release命令
  6. rpm queryrpm查询
  7. rpm macrorpm宏
  8. hostnamectl commandhostnamectl命令

CentOS版本号是什么意思? (What does CentOS Version Number Means?)

CentOS version have three parts.

CentOS版本包括三个部分。

  1. Major Version: Major release version number主要版本:主要发行版本号
  2. Minor Version: Minor release version number次要版本:次要发行版本号
  3. Monthstamp: codebase month and year timestampMonthstamp:代码库的月份和年份时间戳

1. / etc / centos-release文件 (1. /etc/centos-release file)

The CentOS specific file, which contains the CentOS release and version details.

特定于CentOS的文件,其中包含CentOS发行版和版本详细信息。


[root@centos ~]# cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core)
[root@centos ~]#
  • Major Version: 8主要版本:8
  • Minor Version: 1次要版本:1
  • Monthstamp: 1911 i.e. November 2019.月戳:1911年,即2019年11月。
Centos Release Version
Centos发行版本

2. / etc / system-release文件 (2. /etc/system-release file)

This file also contains the same information as the centos-release file.

该文件还包含与centos-release文件相同的信息。


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

3. / etc / os-release文件 (3. /etc/os-release file)

This file contains the Linux OS information. You can get the major version number from this file.

该文件包含Linux OS信息。 您可以从该文件中获取主要版本号。


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

4. / etc / redhat-release文件 (4. /etc/redhat-release file)

CentOS is built on top of RedHat Linux distribution. This file also contains the same information as the centos-release file.

CentOS建立在RedHat Linux发行版之上。 该文件还包含与centos-release文件相同的信息。


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

5. lsb_release命令 (5. lsb_release command)

This command doesn’t come pre-installed with the CentOS server. You can install it using the following command.

CentOS服务器未预安装此命令。 您可以使用以下命令进行安装。


[root@centos ~]# yum install redhat-lsb

Then check the CentOS version using the following command.

然后使用以下命令检查CentOS版本。


[root@centos ~]#  lsb_release -d
Description:    CentOS Linux release 8.1.1911 (Core)
[root@centos ~]#

6. rpm查询 (6. rpm query)

We can query the rpm package manager to get the CentOS version information.

我们可以查询rpm软件包管理器以获取CentOS版本信息。


[root@centos ~]# rpm -q centos-release
centos-release-8.1-1.1911.0.8.el8.x86_64
[root@centos ~]#

7. rpm宏 (7. rpm macro)

Here is a simple rpm macro evaluation to get the CentOS major version.

这是获得CentOS主版本的简单rpm宏评估。


[root@centos ~]# rpm -E %{rhel}
8
[root@centos ~]#

8. hostnamectl命令 (8. hostnamectl command)

The hostnamectl command can be used to get the system information. It also reveals the Operating System version.

hostnamectl命令可用于获取系统信息。 它还显示了操作系统版本。


[root@centos ~]# hostnamectlStatic hostname: localhost.localdomain
Transient hostname: li1176-240.members.linode.comIcon name: computer-vmChassis: vmMachine ID: c2a4bfa7e0c74457b3a978656ab959e8Boot ID: c89bae2d3ec7493987a455bfa15e4818Virtualization: kvmOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 3.10.0-1062.12.1.el7.x86_64Architecture: x86-64
[root@centos ~]#
[root@centos ~]#
[root@centos ~]# hostnamectl | grep "Operating System"Operating System: CentOS Linux 7 (Core)
[root@centos ~]#

Are you wondering why this command is printing CentOS 7, whereas others are printing CentOS 8?

您是否想知道为什么此命令打印CentOS 7,而其他命令打印CentOS 8?

It’s because the hostnamectl command doesn’t work in Docker containers. This command output is from my own VPS machine whereas the other commands output is from my local Docker CentOS 8 container.

这是因为hostnamectl命令在Docker容器中不起作用。 该命令输出来自我自己的VPS机器,而其他命令输出来自我的本地Docker CentOS 8容器

如何以编程方式检查CentOS版本? (How to Check CentOS Version Programatically?)

I am a Java and Python programmer. Let’s see how to find the CentOS version in Java and Python programs.

我是Java和Python程序员。 让我们看看如何在Java和Python程序中找到CentOS版本。

1. Java程序以打印CentOS版本 (1. Java Program to Print CentOS Version)

There is no specific Java class that provides operating system information.

没有提供操作系统信息的特定Java类。

I am just reading the /etc/centos-release file and then printing it to the console.

我只是在读取/ etc / centos-release文件,然后将其打印到控制台。


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;public class CentOSVersion {public static void main(String[] args) throws IOException {String centosVersion = new String(Files.readAllBytes(Paths.get("/etc/centos-release")));System.out.println(centosVersion);}}

2.打印CentOS版本的Python程序 (2. Python Program to Print CentOS Version)

We can use the platform module to get the operating system information.

我们可以使用platform模块来获取操作系统信息。


# Python 3 Scriptimport platformprint('Server Details:', platform.linux_distribution())

I am running this on my CentOS 7 VPS server, where Python is pre-installed.

我正在预先安装了Python的CentOS 7 VPS服务器上运行此程序。


[root@centos ~]# python3 centos-version.py
Server Details: ('CentOS Linux', '7.7.1908', 'Core')
[root@centos ~]#

结论 (Conclusion)

There are many ways to find out the CentOS version information. We also learned how to get the CentOS version in Python and Java programs.

有很多找到CentOS版本信息的方法。 我们还学习了如何在Python和Java程序中获得CentOS版本。

翻译自: https://www.journaldev.com/39919/how-to-check-centos-version

如何检查CentOS版本– 8种方法相关推荐

  1. centos下两种方法安装git

    centos 5 64位下两种方法安装git 这里来给大家介绍下编译安装和yum安装git.   系统:centos 5.5 64位   需要的软件包:git-latest.tar.gz epel-r ...

  2. linux centos安装git,centos下两种方法安装git–转载

    今天下个包需要使用git,网上找了下看到大多数只有编译安装,并且编译安装还有错,不知道他们也没有实验过,这里我来给大家介绍下编译安装和yum安装git. 系统:centos 5.5 需要的软件包:gi ...

  3. windows查看mysql版本(三种方法)

    方法一:在mysql的命令窗口状态下:status;回车即可 方法二:在cmd命令状态下:mysql --help    回车即可 方法三:在mysql命令状态下:select version();回 ...

  4. 如何查看CentOS版本

    转载来源:https://linuxconfig.org/how-to-check-centos-version 如何查看CentOS版本 有几种方法可以检查系统上运行的CentOS版本.检查Cent ...

  5. java检测ubuntu_在Ubuntu、Debian、CentOS Linux中检查Java版本的方法

    本文介绍在Linux操作系统中使用命令行来检查所安装的Java版本(Java Version),当安装需要特定版本的Java的应用程序时,这很有用.该方法适用于Ubuntu.Debian.CentOS ...

  6. yum更新php版本,CentOS 5.4 通过yum升级PHP到5.3版本的两种方法

    CentOS5.4的php版本默认为5.1.6,然后在5.2.9版本之前的的php都存在一个漏洞,但是目前网上很多地方都无法使用yum update php*升级到5.3,经过搜索国外资料,现在终于找 ...

  7. 检查 Oracle 版本的 7 种方法

    以下是检查您正在运行的 Oracle 数据库版本的七种方法. 他们是: V$VERSION视图. V$INSTANCE视图. PRODUCT_COMPONENT_VERSION视图. SQL 开发者图 ...

  8. 查看linux系统版本centos,CentOS下查看系统版本的4种方法

    Linux有很多的发行版,不同的版本会有一些细微区别,所以经常需要查看服务器系统的版本号. 下面来看下CentOS下如何查看CentOS版本. 方法1:cat /etc/issue 执行命令:[www ...

  9. 通过命令查看CentOS版本的几种方法,经过搜集整理得到

    查看CentOS版本方法 命令1: rpm -q centos-release 命令2: yum install redhat-lsb -y lsb_release -a 这个命令适用于所有的linu ...

最新文章

  1. table row设置cell的html,display:table、display:table-row和display:table-cell的用法_html/css_WEB-ITnose...
  2. mmap mprotect详解
  3. 清华团队研发,首款国产电力电子仿真软件来啦~已捐赠哈工大、海工大、清华使用!...
  4. 计算机专业考研过关率高么,考研过国家线的几率有多大?被刷的有多少?
  5. 顺丰快递,果然不一般!
  6. 程序设计实验与上机考试教程 全国计算机等级考试二级vb模拟试题,程序设计基础实验与上机考试教程...
  7. rhel6.1 kvm安装virtio驱动
  8. 印象笔记等App被点名:违法收集公民个人信息
  9. luogu_1984 [SDOI2008]烧水问题
  10. 编译器说 Lambda 表达式中的变量必须是 final 的,我偏不信 | 原力计划
  11. DZ论坛php代码,Discuz!代码大全 - Discuz!-安装使用 - Discuz! 官方站 - Powered by Discuz!...
  12. 一键批量修改文件夹名称
  13. 一种用于指导模拟 IC 布局的定制图神经网络模型
  14. Excel中自动按照货物名称实现结余累计的示例
  15. 2019年,线下营销有哪些重要趋势?
  16. ramdisk和linux PE,[PE教程]WINPE下如何再建一个Ramdisk盘
  17. 学计算机电脑屏幕小可以吗,电脑显示器大小怎么调整
  18. 【转载】显卡PM手记-----4850显卡的诞生
  19. Flutter flutter验证手机号码
  20. 牛客网 精品课程 《直通BAT面试算法精讲课》 优惠码立减10元

热门文章

  1. QT生成在Windows下有图标的exe文件(IDE=QT Creator)
  2. 【整理】C#2.0特性之局部类、空属类型和静态类
  3. 解析:如何在 ASP.NET 中下载文件
  4. #语音信号处理基础(十一)——梅尔倒谱系数的提取
  5. [转载] numpy.argmin 使用
  6. JAVA基础-类型转换
  7. Weblogic的安装与卸载
  8. Oracel 格式化日期 to_char()
  9. [svc]centos7的服务治理-systemd
  10. java基础循环 for 、switch 、while 、do while、