如何从命令行获取Linux版本
从下面的链接下载并以PDF格式支持本文。
theロード下载PDF指南
关门
前言
给定最低版本的Linux系统,我如何知道我正在使用哪个发行版和哪个发行版?这是一个重要的问题。首先,您可以考虑键入uname -a,但这不能提供所有必要的信息。幸运的是,几乎每个发行版都有一个保存此宝贵数据的文件。
这是/ etc / os-release文件。前面已经描述了cat命令的用法,您可能会猜想它会如何出现。因此,您只需执行以下操作,就会很高兴得到想要的东西。
$ cat /etc/os-release NAME="Ubuntu" VERSION="18.04.2 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.2 LTS" VERSION_ID="18.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=bionic UBUNTU_CODENAME=bionic
另一方面,Uname提供以下系统信息:
- -a,–全部 按照以下顺序输出所有信息:但是,如果未知,请省略-p和-i。
- -s,-内核名称 打印内核名称
- -n,–nodename 打印网络节点的主机名
- -r,–内核释放 打印内核发行版
- -v,–内核版本 显示内核版本
- -m,–机器 打印机硬件名称
- -p,–处理器 打印处理器类型(非便携式)
- -i,–硬件平台 打印硬件平台(非便携式)
- -版本 输出uname版本信息并退出
- -o,–操作系统 (主要输出GNU / Linux)
使用uname的例子
$ uname -o GNU/Linux $ uname -m x86_64 $ uname -r 4.15.0-54-generic $ uname -s Linux $ uname -a Linux cloudstack 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
如上所述,我无法使用uname命令找到发行版和发行版。
使用lsb_release命令
在基于Debian的Linux发行版上,可以使用lsb_release命令输出特定于发行版的信息。
可用选项:
-v, --version: Show the version of the LSB against which your current installation is compliant. -i, --id: Display the distributor's ID. -d, --description: Display a description of the currently installed distribution. -r, --release: Display the release number of the currently installed distribution. -c, --codename: Display the code name of the currently installed distribution. -a, --all: Display all of the above information. -s, --short: Use the short output format for any information displayed. This format omits the leading header(s). -h, --help: Show summary of options.
请参见下面的示例。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
$ lsb_release -c
Codename: buster
$ lsb_release -d
Description: Debian GNU/Linux 10 (buster)
$ lsb_release -i
Distributor ID: Debian
使用hostnamectl命令
对于使用Systemd init的Linux系统,您可以从hostnamectl命令的输出中获取系统信息,例如操作系统,内核版本和CPU体系结构。
[email protected]:~# hostnamectl Static hostname: debian10 Icon name: computer-vm Chassis: vm Machine ID: 2e5ced54e5274424b2165b459a18372a Boot ID: e21975d65c53409497466bfbce9cc193 Virtualization: kvm Operating System: Debian GNU/Linux 10 (buster) Kernel: Linux 4.19.0-5-amd64 Architecture: x86-64
请在下面查看可用选项的完整列表:
$ hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[[email protected]]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host
See the hostnamectl(1) man page for details.
检查/ etc / issue的内容
显示/ etc / issue的内容。
$ cat /etc/issue
Debian GNU/Linux 10 n l
结论
如您所知,查找发行版和发行版很容易。我希望它将是有用的。
另请阅读:
如何检查Linux系统上的CPU使用率/利用率
如何使用Linux find命令查找文件
如何在Ubuntu 18.04 / Debian 10上设置系统范围的代理
如何在Ubuntu 18.04 / Ubuntu 16.04 / CentOS 7上设置Squid代理
Nginx和Apache Proxy背后的Grafana
从下面的链接下载并以PDF格式支持本文。
theロード下载PDF指南
关门