关键字: Linux 版本信息
Linux下获取版本信息的方法有很多, 有用cat的,也有用uname的.但我发现获取版本信息最完整的是 lsb_release

[root@localhost RucLinux]# yum install redhat-lsb -y
[root@localhost RucLinux]# lsb_release --h
FSG lsb_release v2.0 prints certain LSB (Linux Standard Base) and
Distribution information.
Usage: lsb_release [OPTION]...
With no OPTION specified defaults to -v.
  -v, --version
    Display the version of the LSB specification against which the distribution is compliant.
  -i, --id
    Display the string id of the distributor.
  -d, --description
    Display the single line text description of the distribution.
  -r, --release
    Display the release number of the distribution.
  -c, --codename
    Display the codename according to the distribution release.
  -a, --all
    Display all of the above information.
  -s, --short
    Use short output format for information requested by other options (or version if none).
  -h, --help
    Display this message.


[root@localhost RucLinux]# lsb_release -a
LSB Version:	:base-4.0-ia32:base-4.0-noarch:core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch
Distributor ID:	CentOS
Description:	CentOS release 6.8 (Final)
Release:	6.8
Codename:	Final


# !/bin/bash
release=`cat /etc/centos-release`
#version=`lsb_release -a|grep -e Dist -e Release|awk -F ":" '{ print $2 }'`
#version=`lsb_release -a|grep -e Release|awk -F ":" '{ print $2 }'`
#version=`lsb_release -a|grep -e Dist|awk -F ":" '{ print $2 }'`
version=`lsb_release -a|grep -e Release|awk -F ":" '{ print $2 }'|awk -F "." '{ print $1 }'|sed 's/ //g'`
#获取到系统版本号的前一位 这里获取到的是6.8中的6
version=`lsb_release -a|grep -e Release|awk -F ":" '{ print $2 }'|sed 's/ //g'`
#获取到系统版本号, 这里获取到的是6.8
version=`lsb_release -a|grep -e ID|awk -F ":" '{ print $2 }'|sed 's/ //g'`
#获取到Distributor ID列中的系统版本名称
version=`lsb_release -a|grep -e Description|awk -F ":" '{ print $2 }'|sed 's/ //g'`
if [ $version == "6" ];then
echo $version
#echo $release


sicnature ---------------------------------------------------------------------
I P 地 址:
区 域 位 置: 美国加利福尼亚圣地亚哥
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source



您的电子邮箱地址不会被公开。 必填项已用 * 标注