如何查看自己的服务器系统是centos还是ununtu?

要查看自己的服务器系统是 CentOS 还是 Ubuntu,可以通过命令行执行一些简单的命令来判断。以下是几种常用的方法:


✅ 方法一:查看 /etc/os-release 文件(推荐)

cat /etc/os-release

输出示例:

  • Ubuntu

    NAME="Ubuntu"
    VERSION="20.04.6 LTS (Focal Fossa)"
    ID=ubuntu
    ...
  • CentOS

    NAME="CentOS Linux"
    VERSION="7 (Core)"
    ID="centos"
    ...

通过 NAMEID 字段可以明确看出系统类型。


✅ 方法二:使用 lsb_release 命令(适用于 Ubuntu/Debian 系)

lsb_release -a

⚠️ 注意:CentOS 默认可能没有安装 lsb_release,如果提示命令不存在,可以跳过此方法或先安装:

yum install -y redhat-lsb-core   # CentOS 7/8

输出如果是类似:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
...

说明是 Ubuntu。


✅ 方法三:查看特定发行版文件

检查是否存在 Ubuntu 特有的文件:

ls /etc/lsb-release

cat /etc/lsb-release 2>/dev/null | grep DISTRIB_ID

检查 CentOS 特有的文件:

cat /etc/centos-release

输出如:

CentOS Linux release 7.9.2009 (Core)

说明是 CentOS。

而 Ubuntu 上这个文件通常不存在。


✅ 方法四:使用 hostnamectl 命令(现代系统支持)

hostnamectl

输出中会包含操作系统信息,例如:

Operating System: Ubuntu 20.04.6 LTS
          Kernel: Linux 5.4.0-150-generic

Operating System: CentOS Linux 7 (Core)

✅ 总结:快速判断命令

你可以直接运行这一行:

grep -E "(PRETTY_NAME|NAME)=" /etc/os-release

输出会清晰显示系统名称,比如:

NAME="Ubuntu"
PRETTY_NAME="Ubuntu 20.04.6 LTS"

NAME="CentOS Linux"
PRETTY_NAME="CentOS Linux 7 (Core)"

结论

  • 出现 Ubuntu → 是 Ubuntu 系统。
  • 出现 CentOSRed Hat → 是 CentOS 系统。

如有需要,也可以贴出输出帮你判断。

未经允许不得转载:ECLOUD博客 » 如何查看自己的服务器系统是centos还是ununtu?