Linux OS のディストリビューションとバージョンを確認する方法

Linux OSの多くのディストリビューションでは/etc/os-releaseが存在し、OSのディストリビューション名やバージョン情報が記載されている。
/etc/os-releaseが存在しない場合もあるが、例えばAmazon Linux 2023では/etc/system-release/etc/amazon-linux-releaseが存在する。 これらの/etc/*-releaseファイルをすべて見ればどこかにはOSのディストリビューション名やバージョン情報を取得できる。

そのためざっくりと確認するには以下のコマンドを実行すればよい。

cat /etc/*-release

Ubuntu

$ cat /etc/*-release | grep -i name
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
...

$ cat /etc/*-release | grep -i version
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_ID="22.04"
VERSION_CODENAME=jammy
...

CentOS

$ cat /etc/*-release | grep -i name
NAME="CentOS Linux"
...

$ cat /etc/*-release | grep -i version
VERSION="7 (Core)"
VERSION_ID="7"
...

Amazon Linux

$ cat /etc/*-release | grep -i name
NAME="Amazon Linux"
...

$ cat /etc/*-release | grep -i version
VERSION="2023"
VERSION_ID="2023"

Debian

$ cat /etc/*-release | grep -i name
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
...

$ cat /etc/*-release | grep -i version
VERSION="11 (bullseye)"
VERSION_ID="11"
...

Rocky Linux

$ cat /etc/*-release | grep -i name
NAME="Rocky Linux"
...

$ cat /etc/*-release | grep -i version
VERSION="8.7 (Green Obsidian)"
VERSION_ID="8.7"
...