要确定系统是 Ubuntu 还是 CentOS,可以通过查看系统的发行版信息来判断。以下是几种常见的方法:
cat
命令查看 /etc/os-release
文件这个文件包含了系统的详细信息,包括发行版名称和版本号。
cat /etc/os-release
输出示例(Ubuntu):
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.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=focal
UBUNTU_CODENAME=focal
输出示例(CentOS):
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"
lsb_release
命令lsb_release
命令可以显示 Linux 标准基础(LSB)的信息。
lsb_release -a
输出示例(Ubuntu):
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
输出示例(CentOS):
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.9.2009 (Core)
Release: 7.9.2009
Codename: Core
/etc/issue
文件这个文件通常包含系统的发行版信息。
cat /etc/issue
输出示例(Ubuntu):
Ubuntu 20.04.3 LTS \n \l
输出示例(CentOS):
CentOS Linux release 7.9.2009 (Core)
Kernel \r on an \m
hostnamectl
命令hostnamectl
命令可以显示系统的详细信息,包括操作系统名称和版本。
hostnamectl
输出示例(Ubuntu):
Static hostname: ubuntu
Icon name: computer-vm
Chassis: vm
Machine ID: 1234567890abcdef1234567890abcdef
Boot ID: 1234567890abcdef1234567890abcdef
Virtualization: kvm
Operating System: Ubuntu 20.04.3 LTS
Kernel: Linux 5.4.0-80-generic
Architecture: x86-64
输出示例(CentOS):
Static hostname: centos
Icon name: computer-vm
Chassis: vm
Machine ID: 1234567890abcdef1234567890abcdef
Boot ID: 1234567890abcdef1234567890abcdef
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
Kernel: Linux 3.10.0-1160.24.1.el7.x86_64
Architecture: x86-64