Unix-like操作系统
1.1、Unix-like简介

因为UNIXThe Open Group拥有的商标(Trade Mark)。 凡是在一定程度上遵守POSIX规范, 但是没有被授权使用UNIX商标的操作系统不能称为UNIX,只能称为Unix-like

1.2、Unix-like发行版分类
Unix-like
├── MINIX
├── BSD-based
│   ├── OpenBSD
│   ├── FreeBSD
│   └── NetBSD
├── GNU/Hurd
│   └── Debian GNU/Hurd
└── GNU/Linux
    ├── Debian GNU/Linux
    ├── Ubuntu
    ├── CentOS
    └── ...
1.3、如何判别是哪个操作系统

Unix-like系统相对比较自由,有时候,我们需要判别是哪个操作系统,分别做不同的操作。

1.3.1、根据是否存在某个配置文件
Alpine Linux

/etc/alpine-release

Arch Linux

/etc/lsb-release

/etc/arch-release

Manjaro Linux

/etc/lsb-release

/etc/manjaro-release

Debian GNU/Linux

/etc/debian_version

Ubuntu

/etc/lsb-release

Fedora

/etc/fedora-release

/etc/system-release

/etc/redhat-release

CentOS

/etc/centos-release

/etc/system-release

/etc/redhat-release

判别的bash脚本如下:

if [ -f "/etc/alpine-release" ] ; then
    echo "your os is AlpineLinux"
elif [ -f "/etc/debian_version" ] ; then
    echo "your os is Debian"
elif [ -f "/etc/lsb-release" ] ; then
    echo "your os is Ubuntu"
elif [ -f "/etc/fedora-release" ] ; then
    echo "your os is Fedora"
elif [ -f "/etc/centos-release" ] ; then
    echo "your os is CentOS"
elif [ -f "/etc/redhat-release" ] ; then
    echo "your os is RHEL"
else
    echo "your os is not recognized!"
fi
1.3.2、根据/etc/os-release文件中的配置

参考

systemd初始化系统提供了一个统一的配置文件/etc/os-release

使用systemd作为初始化系统的操作系统有如下:

系统名称系统版本
Debian GNU/Linux>=8
Ubuntu>=16.04
CentOS>=7
Fedora>=15

判别的bash脚本如下:

local id=`grep "^ID=" /etc/os-release | awk -F= '{print $2}'`
if [ "$id" == "alpine" ] ; then
    echo "your os is AlpineLinux"
elif [ "$id" == "debian" ] ; then
    echo "your os is Debian"
elif [ "$id" == "ubuntu" ] ; then
    echo "your os is Ubuntu"
elif [ "$id" == "fedora" ] ; then
    echo "your os is Fedora"
elif [ "$id" == "\"centos\"" ] ; then
    echo "your os is CentOS"
elif [ "$id" == "redhat" ] ; then
    echo "your os is RHEL"
else
    echo "your os is not recognized!"
fi