cat /proc/version

推荐使用此方法获取Linux版本信息

  • 查看显示内存中kernel相关的版本、编译等信息
  • Ubuntu和CentOS通用,可以显示内核版本同时显示发行版本
sun@u20a:/root$ cat /proc/version
Linux version 5.4.0-77-generic (buildd@lgw01-amd64-028) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021
[root@C8-186 ~]# cat /proc/version
Linux version 4.18.0-147.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)) #1 SMP Wed Dec 4 21:51:45 UTC 2019

uname -a

  • uname命令用来查看系统信息,Ubuntu和CentOS通用
  • 只有内核版本,没有发行版本
sun@u20a:/root$ uname -a
Linux u20a 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@C8-186 ~]# uname -a
Linux C8-186 4.18.0-147.el8.x86_64 #1 SMP Wed Dec 4 21:51:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • uname详细信息
sun@u20a:/root$ whatis uname
uname (1)            - print system information
sun@u20a:/root$ uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type (non-portable)
  -i, --hardware-platform  print the hardware platform (non-portable)
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

cat /etc/issue

不推荐,但是可以快速取到Ubuntu发行版本号

  • /etc/issue文件是Linux系统开机启动时在命令行界面弹出的欢迎语句文件
  • Ubuntu中记录了发行版本名,但CentOS没有
sun@u20a:/root$ cat /etc/issue
Ubuntu 20.04.2 LTS \n \l
[root@C8-186 ~]# cat /etc/issue
\S
Kernel \r on an \m

lsb_release -a

  • lsb_release:prints certain LSB (Linux Standard Base) and Distribution information.
  • 专门用来查看当前系统的发行版信息的命令
  • Ubuntu默认已安装,但最小化安装CentOS没有安装
sun@u20a:/root$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
  • CentOS需要额外安装软件包
[root@C8-186 ~]# lsb_release -a
-bash: lsb_release: command not found
[root@C8-186 ~]# yum -y install lsb_release
BaseOS                                                                                                                                      31 kB/s | 3.9 kB     00:00    
AppStream                                                                                                                                   37 kB/s | 4.3 kB     00:00    
EPEL                                                                                                                                        32 kB/s | 4.7 kB     00:00    
extras                                                                                                                                      12 kB/s | 1.5 kB     00:00    
centosplus                                                                                                                                  12 kB/s | 1.5 kB     00:00    
No match for argument: lsb_release
Error: Unable to find a match: lsb_release
[root@C8-186 ~]# yum provides lsb_release
Last metadata expiration check: 0:00:16 ago on Tue 13 Jul 2021 07:05:20 PM CST.
redhat-lsb-core-4.1-47.el8.i686 : LSB Core module support
Repo        : AppStream
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-47.el8.x86_64 : LSB Core module support
Repo        : AppStream
Matched from:
Filename    : /usr/bin/lsb_release

[root@C8-186 ~]# yum -y install redhat-lsb-core-4.1-47.el8.x86_64
#……省略的安装信息
Installed:
  redhat-lsb-core-4.1-47.el8.x86_64      at-3.1.20-11.el8.x86_64            avahi-libs-0.7-20.el8.x86_64                       cups-libs-1:2.2.6-38.el8.x86_64          
  ed-1.14.2-4.el8.x86_64                 mailx-12.5-29.el8.x86_64           ncurses-compat-libs-6.1-7.20180224.el8.x86_64      patch-2.7.6-11.el8.x86_64                
  psmisc-23.1-5.el8.x86_64               spax-1.5.3-13.el8.x86_64           time-1.9-3.el8.x86_64                              util-linux-user-2.32.1-27.el8.x86_64     
  cups-client-1:2.2.6-38.el8.x86_64      liblockfile-1.14-1.el8.x86_64      redhat-lsb-submod-security-4.1-47.el8.x86_64       esmtp-1.2-15.el8.x86_64                  
  libesmtp-1.0.6-18.el8.x86_64          

Complete!
[root@C8-186 ~]# lsb_release 
LSB Version:	:core-4.1-amd64:core-4.1-noarch
[root@C8-186 ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 8.1.1911 (Core) 
Release:	8.1.1911
Codename:	Core
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐