Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
45
Help us understand the problem. What is going on with this article?
@oo2kazuma

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

このマシンの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

45
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
45
Help us understand the problem. What is going on with this article?