99
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linux OSの種類とバージョンの調べ方

Last updated at Posted at 2017-09-19

このマシンのOSなんだっけ。
そんな時は、何も考えず下記のコマンドをコピペ実行!
CentOSでもRedHat EnterpriseでもUbuntu、Alpine、Fedore、Debian、SUSE Linux、Solarisでも問題なし!(たぶん。)

■コマンド

$ grep -H "" /etc/*version ; grep -H "" /etc/*release

なお、 grep -H "" /etc/{*version,*release}だと上手くDebian7の環境で{}のワイルドカードが正しく動作しなかった。。

■こんな長いコマンド覚えられない!

覚えなくてOK。
要は
cat /etc/*release
cat /etc/*version
すればどんなOSか分かるということです。

■動作確認済み

■CentOS6.9

$ grep -H "" /etc/*version ; grep -H "" /etc/*release
grep: /etc/*version: そのようなファイルやディレクトリはありません
/etc/centos-release:CentOS release 6.9 (Final)
/etc/redhat-release:CentOS release 6.9 (Final)
/etc/system-release:CentOS release 6.9 (Final)

■Debian7

$ grep -H "" /etc/*version ; grep -H "" /etc/*release
/etc/debian_version:7.11
/etc/os-release:PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
/etc/os-release:NAME="Debian GNU/Linux"
/etc/os-release:VERSION_ID="7"
/etc/os-release:VERSION="7 (wheezy)"
/etc/os-release:ID=debian
/etc/os-release:ANSI_COLOR="1;31"
/etc/os-release:HOME_URL="http://www.debian.org/"
/etc/os-release:SUPPORT_URL="http://www.debian.org/support/"
/etc/os-release:BUG_REPORT_URL="http://bugs.debian.org/"

■Raspbian8の場合

$ grep -H "" /etc/*version ; grep -H "" /etc/*release
/etc/debian_version:8.0
/etc/os-release:PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
/etc/os-release:NAME="Raspbian GNU/Linux"
/etc/os-release:VERSION_ID="8"
/etc/os-release:VERSION="8 (jessie)"
/etc/os-release:ID=raspbian
/etc/os-release:ID_LIKE=debian
/etc/os-release:HOME_URL="http://www.raspbian.org/"
/etc/os-release:SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
/etc/os-release:BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

■Ubuntu 14

$ grep -H "" /etc/*version ; grep -H "" /etc/*release
/etc/debian_version:jessie/sid
/etc/lsb-release:DISTRIB_ID=Ubuntu
/etc/lsb-release:DISTRIB_RELEASE=14.04
/etc/lsb-release:DISTRIB_CODENAME=trusty
/etc/lsb-release:DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
/etc/os-release:NAME="Ubuntu"
/etc/os-release:VERSION="14.04.5 LTS, Trusty Tahr"
/etc/os-release:ID=ubuntu
/etc/os-release:ID_LIKE=debian
/etc/os-release:PRETTY_NAME="Ubuntu 14.04.5 LTS"
/etc/os-release:VERSION_ID="14.04"
/etc/os-release:HOME_URL="http://www.ubuntu.com/"
/etc/os-release:SUPPORT_URL="http://help.ubuntu.com/"
/etc/os-release:BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

■Alpine 3.9

/usr/src/app # grep -H "" /etc/*version ; grep -H "" /etc/*release
grep: /etc/*version: No such file or directory
/etc/alpine-release:3.9.4
/etc/os-release:NAME="Alpine Linux"
/etc/os-release:ID=alpine
/etc/os-release:VERSION_ID=3.9.4
/etc/os-release:PRETTY_NAME="Alpine Linux v3.9"
/etc/os-release:HOME_URL="https://alpinelinux.org/"
/etc/os-release:BUG_REPORT_URL="https://bugs.alpinelinux.org/"

■参考

CentOS、UbuntuなどLinux OSのバージョン確認をするコマンド | UX MILK http://uxmilk.jp/13610
LinuxのOSバージョン情報を確認する http://uguisu.skr.jp/Windows/linux_os_version.html
Solarisのバージョンを確認する方法 - ablog http://d.hatena.ne.jp/yohei-a/20090626/1246023366

99
67
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
99
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?