要查看服务器系统是 CentOS 还是 Ubuntu,可以通过以下命令快速识别:
方法 1:检查 /etc/os-release 文件
cat /etc/os-release
- CentOS 会显示
ID="centos"或类似信息。 - Ubuntu 会显示
ID=ubuntu或类似信息。
方法 2:检查 /etc/issue 文件
cat /etc/issue
- 通常会直接显示系统名称(如
Ubuntu 20.04或CentOS Linux 7)。
方法 3:使用 lsb_release 命令
lsb_release -a
- 如果已安装
lsb-release包,会输出详细的发行版信息(适用于 Ubuntu/Debian,CentOS 可能需要手动安装此包)。
方法 4:检查 /etc/redhat-release(仅限 CentOS/RHEL)
cat /etc/redhat-release
- CentOS 会显示类似
CentOS Linux release 7.9.2009的信息。 - Ubuntu 无此文件。
方法 5:使用 hostnamectl 命令(systemd 系统)
hostnamectl
- 在
Operating System或Kernel行中会显示系统类型。
快速总结判断
- 有
/etc/redhat-release文件 → CentOS/RHEL。 - 有
/etc/lsb-release或显示Ubuntu→ Ubuntu。 - 其他情况:结合上述命令综合判断。
示例输出对比
-
CentOS:
$ cat /etc/os-release NAME="CentOS Linux" ID="centos" -
Ubuntu:
$ cat /etc/os-release NAME="Ubuntu" ID=ubuntu
根据这些特征即可轻松区分系统类型。
云服务器