CentOS6/7/8通用查看系統版本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技術主要講述技術,版本,系統網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/it_535.html