Linux下获取系统版本信息的方法

2017年03月15日

原创内容,转载请注明出处: http://www.myzhenai.com.cn/post/2472.html http://www.myzhenai.com/thread-17980-1-1.html
关键字: 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.
Options:
  -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'`
#获取到Description列中的系统版本名称
if [ $version == "6" ];then
echo $version
fi
#echo $release



sicnature ---------------------------------------------------------------------
Your current IP address is: 54.92.178.105
Your IP address location: 美国
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 海南仙岛海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://www.myzhenai.com.cn/post/2472.html

没有评论

发表评论

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