查看inux系統類型和版本

 

  當咱們使用一臺新的linux服務器的時候,爲了區分他們的命令,咱們首先第一步就是要搞清楚這個系統的類型和版本號,據此再來使用對應的命令。linux

  下面來看看能夠使用如下基本命令來查看 Linux 發行版名稱和版本號。ubuntu

  • uname 命令centos

  • lsb_release 命令服務器

  • /etc/*-release 文件工具

  • /proc/version 文件spa

  • dmesg 命令操作系統

  • YUM 或 DNF 命令.net

  • RPM 命令命令行

  • APT-GET 命令unix

 

方法 1: uname 命令

 

uname(unix name 的意思) 是一個打印系統信息的工具,包括內核名稱、版本號、系統詳細信息以及所運行的操做系統等等。

 

[root@VM_71_251_centos ~]# uname -a
Linux VM_71_251_centos 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

 

方法 2: lsb_release 命令

  LSB(Linux 標準庫Linux Standard Base)可以打印發行版的具體信息,包括髮行版名稱、版本號、代號等。

  1.確認lsb_release是否安裝

  

就說明沒有安裝。

2.安裝lsb_release

使用yum安裝lsb,具體命令以下:yum install -y redhat-lsb

  安裝完成以後,就能夠使用這個命令查看了:

  

 

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

release 文件一般被視爲操做系統的標識。在 /etc 目錄下放置了不少記錄着發行版各類信息的文件,每一個發行版都各自有一套這樣記錄着相關信息的文件。下面是一組在 Ubuntu/Debian 系統上顯示出來的文件內容。

# cat /etc/issue

Ubuntu 16.04.3 LTS n l

 

# cat /etc/issue.net

Ubuntu 16.04.3 LTS

 

# cat /etc/lsb-release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=16.04

DISTRIB_CODENAME=xenial

DISTRIB_DESCRIPTION="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

CentOS release 6.9 (Final)

 

# cat /etc/fedora-release

Fedora release 27 (Twenty Seven)

 

# 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

Fedora release 27 (Twenty Seven)

 

# cat /etc/system-release

Fedora release 27 (Twenty Seven)

 

方法 4: /proc/version 文件

 

這個文件記錄了 Linux 內核的版本、用於編譯內核的 gcc 的版本、內核編譯的時間,以及內核編譯者的用戶名。

 

# cat /proc/version

Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.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] Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017

[ 0.001000] SELinux: Initializing.

[ 0.001000] SELinux: Starting in permissive mode

[ 0.470288] SELinux: Registering netfilter hooks

[ 0.616351] Linux agpgart interface v0.103

[ 0.630063] usb usb1: Manufacturer: Linux 4.12.14-300.fc26.x86_64 ehci_hcd

[ 0.688949] usb usb2: Manufacturer: Linux 4.12.14-300.fc26.x86_64 ohci_hcd

[ 2.564554] SELinux: Disabled at runtime.

[ 2.564584] SELinux: Unregistering netfilter hooks

 

方法 6: Yum/Dnf 命令

 

Yum(Yellowdog 更新器修改版Yellowdog Updater Modified)是 Linux 操做系統上的一個包管理工具,而 yum 命令被用於一些基於 RedHat 的 Linux 發行版上安裝、更新、查找、刪除軟件包。

 

# yum info nano

Loaded plugins: 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 : 440 k

Repo : base/7/x86_64

Summary : A small text editor

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

License : GPLv3+

Description : GNU nano is a small and friendly text editor.

 

下面的 yum repolist 命令執行後顯示了 yum 的基礎源倉庫、額外源倉庫、更新源倉庫都來自 CentOS 7 倉庫。

 

# yum repolist

Loaded plugins: 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_64 CentOS-7 - Base 9591

extras/7/x86_64 CentOS-7 - Extras 388

updates/7/x86_64 CentOS-7 - Updates 1929

repolist: 11908

 

使用 dnf 命令也一樣能夠查看發行版名稱和版本號。

 不支持dnf命令的話,安裝dnf命令參考:https://blog.csdn.net/ximingren/article/details/79189179

# dnf info nano

Last metadata expiration check: 0:01:25 ago on Thu Feb 15 01:59:31 2018.

Installed Packages

Name : nano

Version : 2.8.7

Release : 1.fc27

Arch : x86_64

Size : 2.1 M

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

Repo : <a href="http://www.jobbole.com/members/system">@System</a>

From repo : fedora

Summary : A small text editor

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

License : GPLv3+

Description : GNU nano is a small and friendly text editor.

 

方法 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

Version table:

* 2.5.3-2ubuntu2 500

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

100 /var/lib/dpkg/status

2.5.3-2 500

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

 

參考:https://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666542178&idx=1&sn=37dc654c72c7f2f0bcf3635dce1e7354&chksm=80dcf0c9b7ab79df93cc419ccc17331a07df6d53134c5c8cdb5986be066ebf5bd6281bf0229c&mpshare=1&scene=1&srcid=1129lU68KUBUGdJflNAF0Ias#rd

相關文章
相關標籤/搜索