查看linux发行版的方法

linux通过伪文件夹系统 /proc ,下的文件 /proc/version。可以查看linux的版本,和发行版,和gcc的信息。 这样就可以确定发行版是centos还是ubuntu或者其他。当然也可以使用命令 lsb_release -a 进行查看

1. 通过 /proc/version 查看发行的版本

代码示例

result=(grep -o -E 'Red Hat|Ubuntu' /proc/version | uniq | head -n 1)
caseresult in
    'Red Hat' )
        echo " Red Hat";
        ;;
    'Ubuntu' )
        echo " Ubuntu";
        ;;
    *)
        echo "other";
        ;;
esac

2. 通过lsb_release 查看发行版本

LSB (Linux Standard Base)
lsb_release -a 可以查看所有的发行版的所有的信息
lsb_release 的参数

  1. -i 显示发行版
  2. -d 显示描述
  3. -r 显示发行版的版本
lsb_release -i
Distributor ID: CentOS

lsb_release -r
Release:        7.4.1708

lsb_release -c
Codename:       Core

lsb_release -d
Description:    CentOS Linux release 7.4.1708 (Core)

获取发行版本
lsb_release -i | awk '{ print3 }'
CentOS
获取发行版的版本
lsb_release -r | awk '{ print2 }'
7.4.1708

其他的方法

通过配置文件中获取,不同发行版名字不同。比如 /etc/issue, /etc/redhat-release

发表评论

邮箱地址不会被公开。