Linux运行版名称,查看 Linux 发行版名称和版本号的 8 种方法

方法 1: lsb_release 命令

LSB(Linux 标准库Linux Standard Base)能够打印发行版的具体信息,包括发行版名称、版本号、代号等。

# lsb_release -a

No LSB modules areavailable.

DistributorID:Ubuntu

Deion:Ubuntu16.04.3LTS

Release:16.04

Codename:xenial

方法 2: /etc/*-release 文件

release 文件通常被视为操作系统的标识。在 /etc 目录下放置了很多记录着发行版各种信息的文件,每个发行版都各自有一套这样记录着相关信息的文件。下面是一组在 Ubuntu/Debian 系统上显示出来的文件内容。

# cat /etc/issue

Ubuntu16.04.3LTSnl

# cat /etc/issue.net

Ubuntu16.04.3LTS

# cat /etc/lsb-release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=16.04

DISTRIB_CODENAME=xenial

DISTRIB_DEION="Ubuntu 16.04.3 LTS"

# cat /etc/os-release

NAME="Ubuntu"

VERSION="16.04.3 LTS (Xenial Xerus)"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu 16.04.3 LTS"

VERSION_ID="16.04"

HOME_URL="http://www.ubuntu.com/"

SUPPORT_URL="http://help.ubuntu.com/"

BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

VERSION_CODENAME=xenial

UBUNTU_CODENAME=xenial

# cat /etc/debian_version

9.3

下面这一组是在 RHEL/CentOS/Fedora 系统上显示出来的文件内容。其中 /etc/redhat-release 和 /etc/system-release 文件是指向 /etc/[发行版名称]-release 文件的一个连接。

# cat /etc/centos-release

CentOSrelease6.9(Final)

# cat /etc/fedora-release

Fedorarelease27(TwentySeven)

# cat /etc/os-release

NAME=Fedora

VERSION="27 (Twenty Seven)"

ID=fedora

VERSION_ID=27

PRETTY_NAME="Fedora 27 (Twenty Seven)"

ANSI_COLOR="0;34"

CPE_NAME="cpe:/o:fedoraproject:fedora:27"

HOME_URL="https://fedoraproject.org/"

SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"

BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Fedora"

REDHAT_BUGZILLA_PRODUCT_VERSION=27

REDHAT_SUPPORT_PRODUCT="Fedora"

REDHAT_SUPPORT_PRODUCT_VERSION=27

PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"

# cat /etc/redhat-release

Fedorarelease27(TwentySeven)

# cat /etc/system-release

Fedorarelease27(TwentySeven)

方法 3: uname 命令

uname(unix name 的意思) 是一个打印系统信息的工具,包括内核名称、版本号、系统详细信息以及所运行的操作系统等等。

# uname -a

Linuxlocalhost.localdomain4.12.14-300.fc26.x86_64#1 SMP Wed Sep 20 16:28:07 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

以上运行结果说明使用的操作系统版本是 Fedora 26。

方法 4: /proc/version 文件

这个文件记录了 Linux 内核的版本、用于编译内核的 gcc 的版本、内核编译的时间,以及内核编译者的用户名。

# cat /proc/version

Linuxversion4.12.14-300.fc26.x86_64([emailprotected])(gccversion7.2.120170915(RedHat7.2.1-2)(GCC))#1 SMP Wed Sep 20 16:28:07 UTC 2017

方法 5: dmesg 命令

dmesg(展示信息display message 或驱动程序信息driver message)是大多数类 Unix 操作系统上的一个命令,用于打印内核的消息缓冲区的信息。

# dmesg | grep "Linux"

[0.000000]Linuxversion4.12.14-300.fc26.x86_64([emailprotected])(gccversion7.2.120170915(RedHat7.2.1-2)(GCC))#1 SMP Wed Sep 20 16:28:07 UTC 2017

[0.001000]SELinux:Initializing.

[0.001000]SELinux:Startinginpermissivemode

[0.470288]SELinux:Registering netfilterhooks

[0.616351]Linux agpgartinterfacev0.103

[0.630063]usbusb1:Manufacturer:Linux4.12.14-300.fc26.x86_64ehci_hcd

[0.688949]usbusb2:Manufacturer:Linux4.12.14-300.fc26.x86_64ohci_hcd

[2.564554]SELinux:Disabled atruntime.

[2.564584]SELinux:Unregistering netfilterhooks

方法 6: Yum/Dnf 命令

Yum(Yellowdog 更新器修改版Yellowdog Updater Modified)是 Linux 操作系统上的一个包管理工具,而 yum 命令被用于一些基于 RedHat 的 Linux 发行版上安装、更新、查找、删除软件包。

# yum info nano

Loadedplugins:fastestmirror,ovl

Loading mirror speeds from cached hostfile

*base:centos.zswap.net

*extras:mirror2.evolution-host.com

*updates:centos.zswap.net

Available Packages

Name:nano

Arch:x86_64

Version:2.3.1

Release:10.el7

Size:440k

Repo:base/7/x86_64

Summary:Asmall text editor

URL:http://www.nano-editor.org

License:GPLv3+

Deion:GNU nanoisasmallandfriendly texteditor.

下面的 yum repolist 命令执行后显示了 yum 的基础源仓库、额外源仓库、更新源仓库都来自 CentOS 7 仓库。

# yum repolist

Loadedplugins:fastestmirror,ovl

Loading mirror speeds from cached hostfile

*base:centos.zswap.net

*extras:mirror2.evolution-host.com

*updates:centos.zswap.net

repo id repo name status

base/7/x86_64CentOS-7-Base9591

extras/7/x86_64CentOS-7-Extras388

updates/7/x86_64CentOS-7-Updates1929

repolist:11908

使用 dnf 命令也同样可以查看发行版名称和版本号。

# dnf info nano

Last metadata expirationcheck:0:01:25ago on ThuFeb1501:59:312018.

Installed Packages

Name:nano

Version:2.8.7

Release:1.fc27

Arch:x86_64

Size:2.1M

Source:nano-2.8.7-1.fc27.src.rpm

Repo: @System

Fromrepo:fedora

Summary:Asmall text editor

URL:https://www.nano-editor.org

License:GPLv3+

Deion:GNU nanoisasmallandfriendly texteditor.

方法 7: RPM 命令

RPM(红帽包管理器RedHat Package Manager)是在 CentOS、Oracle Linux、Fedora 这些基于 RedHat 的操作系统上的一个强大的命令行包管理工具,同样也可以帮助我们查看系统的版本信息。

# rpm -q nano

nano-2.8.7-1.fc27.x86_64

方法 8: APT-GET 命令

Apt-Get(高级打包工具Advanced Packaging Tool)是一个强大的命令行工具,可以自动下载安装新软件包、更新已有的软件包、更新软件包列表索引,甚至更新整个 Debian 系统。

# apt-cache policy nano

nano:

Installed:2.5.3-2ubuntu2

Candidate:2.5.3-2ubuntu2

Versiontable:

*2.5.3-2ubuntu2500

500http://nova.clouds.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages

100/var/lib/dpkg/status

2.5.3-2500

500http://nova.clouds.archive.ubuntu.com/ubuntu xenial/main amd64 Packages返回搜狐,查看更多

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值