【已解决】Linux系统中如何判断当前Linux是什么类型和什么版本即是哪个发行版

【背景】

拿到一个Linux的服务器。

想要搞清楚,是哪个发行版,比如CentOS,Ubuntu等等。

以便于后续使用yum还是apt-get去install软件,以及做不同的配置。

 

【折腾过程】

1.通过uname,看不到想要的,只看到Linux:

[root@bogon /]# uname -a
Linux bogon 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

2.搜:

how check which linux distribution

参考:

HowTo: Find Out My Linux Distribution Name and Version

去试试:

[root@bogon ~]# cat /etc/*-release
CentOS release 6.6 (Final)
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
CentOS release 6.6 (Final)
CentOS release 6.6 (Final)

很明显可以看出来,是CentOS。

3.再去试试:

[root@bogon ~]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.6 (Final)
Release:        6.6
Codename:       Final

4.以及:

 

[root@bogon ~]# cat /proc/version
Linux version 2.6.32-504.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014

 

【总结】

Linux中,通过:

cat /etc/*-release

或:

 

lsb_release -a

 

或:

cat /proc/version

即可看出是哪个Linux的发行版。

 

其中最推荐的是用:

lsb_release –a

 

【后记 2015-09-09】

1.后来在一个Linux系统,其实自己已经知道不是CentOS就是Ubuntu,但是想要确认到底是哪个系统。

结果去参考上述的办法,竟然:

没有lsb

crifan@crifan:~$ lsb_release -a
-bash: lsb_release: command not found
crifan@crifan:~$ yum search lsb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * epel: mirror.smartmedia.net.id
 * extras: mirrors.linode.com
 * updates: mirrors.linode.com
================================================================ N/S matched: lsb =================================================================
redhat-lsb-core.i686 : LSB Core module support
redhat-lsb-core.x86_64 : LSB Core module support
redhat-lsb-cxx.i686 : LSB CXX module support
redhat-lsb-cxx.x86_64 : LSB CXX module support
redhat-lsb-desktop.i686 : LSB Desktop module support
redhat-lsb-desktop.x86_64 : LSB Desktop module support
redhat-lsb-languages.i686 : LSB Languages module support
redhat-lsb-languages.x86_64 : LSB Languages module support
redhat-lsb-printing.i686 : LSB Printing module support
redhat-lsb-printing.x86_64 : LSB Printing module support
redhat-lsb-submod-multimedia.i686 : LSB Multimedia submodule support
redhat-lsb-submod-multimedia.x86_64 : LSB Multimedia submodule support
redhat-lsb-submod-security.i686 : LSB Security submodule support
redhat-lsb-submod-security.x86_64 : LSB Security submodule support
redhat-lsb-supplemental.x86_64 : LSB supplemental dependencies required by LSB certification tests
redhat-lsb-trialuse.i686 : LSB Trialuse module support
redhat-lsb-trialuse.x86_64 : LSB Trialuse module support
redhat-lsb.i686 : Implementation of Linux Standard Base specification
redhat-lsb.x86_64 : Implementation of Linux Standard Base specification

  Name and summary matches only, use "search all" for everything.

 

2.然后 cat /proc/version也没用:

crifan@crifan:~$ cat /proc/version
Linux version 4.1.5-x86_64-linode61 (maker@build) (gcc version 4.7.2 (Debian 4.7.2-5) ) #7 SMP Mon Aug 24 13:46:31 EDT 2015

3.最后还是去参考:

HowTo: Find Out My Linux Distribution Name and Version

去试了试:

crifan@crifan:~$ cat /etc/*-release
CentOS Linux release 7.1.1503 (Core) 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.1.1503 (Core) 
CentOS Linux release 7.1.1503 (Core) 
crifan@crifan:~$

所以,新的结论是:

如果:

像此处的CentOS 7中没有lsb_release

并且cat /proc/version没有输出对应的系统的类型和版本

那么:

可以去用:

cat /etc/*-release

即可看到输出中的信息中有

CentOS Linux release 7.1.1503

可以看出是CentOS,版本是7.1.1503



发表评论

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

无觅相关文章插件,快速提升流量