识别CentOS和Ubuntu的系统版本

1、用 lsb-release

#!/bin/bash
Install_LSB()
{
        if [ "$PM" = "yum" ]; then
                yum install -y redhat-lsb centos-release
        elif [ "$PM" = "apt" ]; then
                apt-get update
                apt-get install -y lsb-release
        fi
}
Install_LSB
lsb_release -d

2、从定义好的配置文件中读取

CentOS 中相关的文件
cat /etc/centos-release
cat /etc/redhat-release (/etc/redhat-release -> centos-release)
cat /etc/system-release (/etc/system-release -> centos-release)
rpm -q centos-release
# rpm -q redhat-release
如果是CentOS7,支持 cat /etc/os-release

Ubuntu 中相关的文件
cat /etc/os-release  (/etc/os-release -> ../usr/lib/os-release)
cat /etc/lsb-release

在CentOS和Ubuntu中也可以这样读系统版本,不过 /etc/issue (登录欢迎信息)有时候是空的
cat /etc/issue
#cat /etc/*elease
for i in $(ls /etc/*release); do echo ===$i===; cat $i; done

3、hostnamectl

在CentOS7和Ubuntu中,通过 hostnamectl 读系统版本
hostnamectl

Ubuntu中这样安装 hostnamectl
apt install -y systemd systemd-services apt-file
apt-file update
apt-file search hostnamectl
/usr/bin/hostnamectl

识别CentOS和Ubuntu的系统版本的更多相关文章

  1. Ubuntu 更新系统版本以及查看当前系统版本的命令

    1. Ubuntu 查看当前系统版本: lsb_release -a 2. Ubuntu 更新系统版本的命令: sudo do-release-upgrade

  2. 云服务器-Ubuntu更新系统版本-更新Linux内核-服务器安全配置优化-防反弹shell

    购入了一台阿里云的ESC服务器,以前都用CentOS感觉Yum不怎么方便,这次选的Ubuntu16.04.7 搭好服务之后做安全检查,发现Ubuntu16.04版本漏洞众多:虽然也没有涉及到16.04 ...

  3. ubuntu查看系统版本和内核版本

    查看系统版本: cat /etc/issue sudo lsb_release -a 查看内核版本: uname -r

  4. ubuntu 查看系统版本信息

    查看cpu信息cat /proc/cpiinfo 查看ubuntu版本:cat /etc/issue 查看系统是32位还是64位方法1:#查看long的位数,返回32或64 getconf LONG_ ...

  5. ubuntu查看系统版本

    1.查看文件信息,包含32-bit就是32位,包含64-bit就是64位 root@HDController:/home/nulige/tools# uname -a Linux HDControll ...

  6. ubuntu 查看系统版本

    在终端中执行下列指令:cat /etc/issue可以查看当前正在运行的 Ubuntu 的版本号: 使用 lsb_release 命令也可以查看 Ubuntu 的版本号,与方法一相比,内容更为详细:

  7. Ubuntu查看系统版本的方法

    1. less /etc/issue 2. less /proc/version 3. uname -a 4. lsb_release -a

  8. Linux下载_Linux系统各种版本ISO镜像下载(redhat,centos,oracle,ubuntu,openSUSE)

    以下是风哥收集的Linux系统各种版本ISO镜像下载,包括redhat,centos,oracle,ubuntu等linux操作系统. Linux下载1:红帽RedHat Linux(RHEL5.RH ...

  9. 查看linux系统版本信息(Oracle Linux、Centos Linux、Redhat Linux、Debian、Ubuntu)

    一.查看Linux系统版本的命令(3种方法) 1.cat /etc/issue,此命令也适用于所有的Linux发行版. [root@S-CentOS home]# cat /etc/issue Cen ...

随机推荐

  1. 字符串格式时间转Date格式

    /** * 字符串时间格式转 Date 格式 * @param strDate * @return */ public static Date getDateTimeByStringTime(Stri ...

  2. BZOJ 5254 [Fjwc2018]红绿灯 (线段树)

    题目大意:一个wly从家走到学校要经过n个红绿灯,绿灯持续时间是$g$,红灯是$r$,所有红绿灯同时变红变绿,交通规则和现实中一样,不能抢红灯,两个红绿灯之间道路的长度是$di$,一共$Q$个询问,求 ...

  3. apache源码编译安装

    源码安装apche 下载apache的源码包文件 访问http://mirror.bit.edu.cn/apache/httpd/,复制如下gz文件的链接地址,并使用wget下载到本地 wget -P ...

  4. Login.hbm.xml

    <?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLI ...

  5. Google C++ Style Guide的哲学

    Google C++ Style Guide并不是一个百科全书,也不是一个C++使用指南,但它描述适用于Google及其开源项目的编码指南,并不追求全面和绝对正确,也有许多人置疑它的一些规则.但作为一 ...

  6. LeetCode【8】. String to Integer (atoi) --java实现

    String to Integer (atoi) Implement atoi to convert a string to an integer. Hint: Carefully consider ...

  7. ACM:动态规划,01背包问题

    题目: 有n件物品和一个容量为C的背包.(每种物品均仅仅有一件)第i件物品的体积是v[i],重量是w[i].选一些物品装到这个背包中,使得背包内物品在整体积不超过C的前提下重量尽量大. 解法:两种思路 ...

  8. rest_framework-认证-总结完结篇

    执行过程 APIView() Ruquest() Authentication() OrderView()APIView() def duspatch: self.initial(request) d ...

  9. luogu 1280 尼克的任务

    题目描述 尼克每天上班之前都连接上英特网,接收他的上司发来的邮件,这些邮件包含了尼克主管的部门当天要完成的全部任务,每个任务由一个开始时刻与一个持续时间构成. 尼克的一个工作日为N分钟,从第一分钟开始 ...

  10. JavaScript中函数作为另一个函数的参数的时候它存在于哪个作用域

    一直对函数作为参数被传递进另外一个函数理解的不是很清除.先看下这段代码吧: function test(fn){ var bar = 1; fn(); } var bar = 99; test(fun ...