uname 命令的输出就可以获取这些信息,但这些信息都是什么,它告诉了你什么?
在这篇文章中,我们将仔细看看 uname 命令的输出,以及一些其他命令和文件提供的版本描述。
使用 uname
每当你在Linux系统终端窗口中发出uname -a命令时,就会显示很多信息。 事实上,每一块显示的信息都会告诉你一些关于系统的不同信息。
uname -a命令=uname -snmrvpioLinux parallels 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux通过help命令可以看到详细的说明uname --helpUsage: 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 or "unknown" -i, --hardware-platform print the hardware platform or "unknown" -o, --operating-system print the operating system --help display this help and exit --version output version information and exit
现在我们通过一个shell来展示下各个的对应关系:
# for option in s n m r v p i o; do echo -n "$option: "; uname -$option; dones: Linux n: parallelsm: x86_64r: 3.10.0-862.11.6.el7.x86_64v: #1 SMP Tue Aug 14 21:49:04 UTC 2018p: x86_64i: x86_64o: GNU/Linux需要注意r: 3.10.0-862.11.6.el7.x86_64这个内核版本3是内核版本10表示主要修订0表示小修862代表最新的补丁#1表示这个版本已经编译了1次(v: #1 SMP Tue Aug 14 21:49:04 UTC 2018)
如果你需要知道你正在运行的发行版是什么版本,uname的输出不会给你太多帮助。内核版本毕竟和发行版不一样。为了获得这些信息,你可以在 Ubuntu 和其他基于 Debian 的系统上使用 lsb_release -r 命令,并显示 Red Hat 的 /etc/redhat-release 文件的内容。
举例在各个系统下命令
Red Hat or CentOS systems# uname -aLinux parallels 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux# lsb_release -aLSB 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-noarchDistributor ID:CentOSDescription:CentOS Linux release 7.5.1804 (Core)Release:7.5.1804Codename:Core# lsb_release -rRelease:7.5.1804# cat /etc/redhat-releaseCentOS Linux release 7.5.1804 (Core)For Debian systems:$ lsb_release -rRelease: 20.04For Red Hat and related systems:$ cat /etc/redhat-releaseRed Hat Enterprise Linux release 8.1 Beta (Ootpa)Using /proc/versionThe /proc/version file can also provide information on your Linux release. The information provided in this file has a lot in common with the uname -a output. Here are some examples.On Ubuntu:$ cat /proc/versionLinux version 5.4.0-37-generic (buildd@lcy01-amd64-001) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #41-Ubuntu SMP Wed Jun 3 18:57:02 UTC 2020On RedHat:$ cat /proc/versionLinux version 4.18.0-107.el8.x86_64 (mockbuild@x86-vm-09.build.eng.bos.redhat.com) (gcc version 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)) #1 SMP Fri Jun 14 13:46:34 UTC 2019
下面是macOS系统的
macOS系统 Show operating system name and more➜ ~ uname -aDarwin Mac 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 DarwinShow Mac OS X operating system version➜ ~ sw_versProductName:Mac OS XProductVersion:10.15.6BuildVersion:19G2021Show Apple hardware and software configuration➜ ~ system_profiler 获取的信息量比较大,需要自己提取system_profiler SPSoftwareDataTypeSoftware: System Software Overview: System Version: macOS 10.15.6 (19G2021) Kernel Version: Darwin 19.6.0 Boot Volume: Macintosh HD Boot Mode: Normal Computer Name: Mac User Name: 隐藏哈 Secure Virtual Memory: Enabled System Integrity Protection: Disabled Time since boot: 3 days 23:53