实战

uname                  # 操作系统名(如 Linux)
uname -a               # 全部信息
uname -r               # 内核版本(如 6.5.0-21-generic)
uname -m               # 架构(x86_64 / aarch64 / armv7l 等)
uname -n               # hostname
uname -o               # OS(GNU/Linux)
uname -s               # 内核名(Linux)
uname -v               # 内核构建版本字符串

实战 2

# 看是 ARM 还是 x86
uname -m
# x86_64    → Intel/AMD 64 位
# aarch64   → ARM 64 位(树莓派 4 / Mac M 系列 / 部分云)
# armv7l    → ARM 32 位

# 看具体发行版(uname 给不出)
cat /etc/os-release
lsb_release -a               # 如果装了 lsb
hostnamectl                  # 系统综合信息

看发行版(额外)

# 通用
cat /etc/os-release
# NAME="Ubuntu"
# VERSION="22.04.4 LTS (Jammy Jellyfish)"
# ...

# Ubuntu / Debian
lsb_release -a

# CentOS / RHEL
cat /etc/redhat-release

# Arch
cat /etc/arch-release

# 内核
uname -r

脚本里用

# 区分发行版做不同的事
if [[ -f /etc/debian_version ]]; then
    sudo apt install $PKG
elif [[ -f /etc/redhat-release ]]; then
    sudo dnf install $PKG
fi