蒙珣的博客

活好当下,做好今天该做的事情。

0%

Linux获取系统版本信息

cat /proc/verison

获取内核信息

1
2
[root@k8s-nodes1 ~]# cat /proc/version
Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

uname -a

获取内核信息

1
2
[root@k8s-nodes1 ~]# uname -a
Linux k8s-nodes1 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

lsb_release -a

  • 获取系统信息
  • 有些系统会没有 lsb_release 命令 yum install -y redhat-lsb
1
2
3
4
5
6
[root@k8s-nodes1 ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.9.2009 (Core)
Release: 7.9.2009
Codename: Core

cat /etc/os-release

获取系统信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@k8s-nodes1 ~]# cat /etc/os-release
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"

cat /etc/redhat-release

仅适用于 Readhat 系的 Linux

1
2
[root@k8s-nodes1 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

hostnamectl

获取系统信息

1
2
3
4
5
6
7
8
9
10
[root@k8s-nodes1 ~]# hostnamectl
Static hostname: k8s-nodes1
Icon name: computer-server
Chassis: server
Machine ID: ab3142cf29f34983b5f55182b177a3e8
Boot ID: e3964313f7f741678d8a0c3f93998be3
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.el7.x86_64
Architecture: x86-64

准确获取系统版本号

方式一

1
sudo cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'

方式二

有些系统会没有 lsb_release 命令

1
lsb_release -a|grep -e Release|awk -F ":" '{ print $2 }' | awk -F "." '{print $1}' | sed 's/[[:space:]]//g'

转自:小菠萝测试笔记