最新活动:电脑PC端+手机端+微网站+自适应网页多模板选择-建站388元起价!!!
要源码
当前位置:主页 > IT知识 > CentOS6/7/8通用查看系统版本IT技术

CentOS6/7/8通用查看系统版本IT技术

时间:2023-05-07 13:05:07 阅读: 文章分类: IT知识 作者: 网站技术员

导读:IT技术IT技术要写一个CentOS系统的初始化脚本,但是CentOS6、CentOS7、CentOS8版本有很多命令都不相同,所以为了让脚本在两个版本之间都可以使用,就需要对宏基电脑技术热线自己组建云电脑技术。

宏基电脑技术热线自己组建云电脑技术

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

通过查找各种资料,我发现基本有下面几种查看系统版本的方法。

方法一

lsb_release -a

[root@centos6 ~]# lsb_release -a LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID:    CentOS Description:    CentOS release 6.9 (Final) Release:    6.9 Codename:    Final

但是,CentOS7.3+里没有lsb_release命令,所以这种seo网站关键词优化方法无法满足我的需要。

方法二

cat /etc/os-release

[root@centos7 app]# cat /etc/os-r网站建设多少钱elease  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"COPY 但是,CentOS6里没有这个文件,所以这个方法也不适用。 但是,CentOS6里没有这个文件,所以这个方法也不适用。

方法三(推荐)

cat /etc/redhat-release or cat /etc/centos-release

cat /etc/redhat-release or cat /etc/centos-release [root@centos6 ~]# cat /etc/redhat-release  CentOS release 6.9 (Final) [root@centos7 app]# cat /etc/redhat-release  CentOS Linux release 7.3.1611 (Core) COPY

可以看到,这个方法在三个版本中都可以使用,可以使用sed命令取版本的值

[root@centos6 ~]# cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/' 6 [root@centos7 ~]# cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/' 7COPY

方法四

rpm -q centos-release

[root@centos6 ~]# rpm -q centos-release centos-release-6-9.el6.12.3.x86_64 [root@centos7 app]# rpm -q centos-release centos-release-7-3.1611.el7.centos.x86_64COPY

关键词标签: 技术 系统 版本

声明: 本文由我的SEOUC技术文章主页发布于:2023-05-07 ,文章CentOS6/7/8通用查看系统版本IT技术主要讲述技术,版本,系统网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/it_535.html

我的IDC 网站建设技术SEOUC.COM
专注网站建设,SEO优化,小程序设计制作搭建开发定制网站等,数千家网站定制开发案例,网站推广技术服务。
  • 5000+合作客服
  • 8年从业经验
  • 150+覆盖行业
  • 最新热门源码技术文章