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

2017年03月15日

原创内容,转载请注明出处: https://www.myzhenai.com.cn/post/2472.html https://www.myzhenai.com/thread-17980-1-1.html
关键字: Linux 版本信息
Linux下获取版本信息的方法有很多, 有用cat的,也有用uname的.但我发现获取版本信息最完整的是 lsb_release

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[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]# 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]# 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.

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[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
[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
[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

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# !/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
# !/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
# !/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 ---------------------------------------------------------------------
I P 地 址: 18.220.140.26
区 域 位 置: 美国俄亥俄
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com/post/2472.html

没有评论

发表回复

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