linux 区分ubuntu还是centos

方法1:lsb_release获取

 lsb_release -a

    Centos如果没用 lsb_release命令需要安安装

sudo yum install -y redhat-lsb

 方法2  os_release获取

cat  /etc/os-release

  Centos查询结果

  linux 区分ubuntu还是centos_第1张图片

  Ubuntu查询结果

  linux 区分ubuntu还是centos_第2张图片

 

  写个测试脚本测试

  

#!/bin/bash

function test_linux_version(){
     if [ `cat /etc/os-release | grep CentOS | wc -l` -ne 0 ]; then
        echo "Linux version is centos"
     elif [ `cat /etc/os-release | grep Ubuntu | wc -l` -ne 0 ]; then
        echo "Linux version is Ubuntu"
     fi
}

test_linux_version

 

你可能感兴趣的:(服务器配置,FAQ,Ubuntu)