1. Posts/

How to check OS and version in Linux

···
linux DevOps

From time to time you end up in a machine running somewhere in the cloud and wonder what OS is running there. You know it's a flavour of Linux, but you don't know which one. Worry not my friend, this post will help you.

Kernel Version

If you want kernel version information, use uname(1).

1
2
$ uname -a
Linux localhost 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
1
2
$ uname -a
Linux 10.0.2.15 4.13.15-300.fc27.x86_64 #1 SMP Tue Nov 21 21:10:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Distribution Information

Information about the distribution varies depending on the distribution. If your distribution supports Linux Standard Base, then we can find that information using lsb_release. It can also be found from *-release files in /etc/ directory.

1
2
3
4
5
6
  $ lsb_release -a
  No LSB modules are available.
  Distributor ID:	Ubuntu
  Description:	Ubuntu 16.04.3 LTS
  Release:	16.04
  Codename:	xenial

On Fedora you may need to install lsb_release.

1
2
3
4
5
6
7
  $ sudo yum install lsb_release -a
  $ lsb_release -a
  LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
  Distributor ID:	Fedora
  Description:	Fedora release 27 (Twenty Seven)
  Release:	27
  Codename:	TwentySeven

Release files

Ubuntu has two release files /etc/lsb-release and /etc/os-release

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Fedoro has /etc/fedora-release, /etc/os-release, /etc/redhat-release, /etc/system-release

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  $ cat /etc/*-release
   sudo cat /etc/*release
  Fedora release 27 (Twenty Seven)
  NAME=Fedora
  VERSION="27 (Cloud Edition)"
  ID=fedora
  VERSION_ID=27
  PRETTY_NAME="Fedora 27 (Cloud Edition)"
  ANSI_COLOR="0;34"
  CPE_NAME="cpe:/o:fedoraproject:fedora:27"
  HOME_URL="https://fedoraproject.org/"
  SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
  BUG_REPORT_URL="https://bugzilla.redhat.com/"
  REDHAT_BUGZILLA_PRODUCT="Fedora"
  REDHAT_BUGZILLA_PRODUCT_VERSION=27
  REDHAT_SUPPORT_PRODUCT="Fedora"
  REDHAT_SUPPORT_PRODUCT_VERSION=27
  PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
  VARIANT="Cloud Edition"
  VARIANT_ID=cloud
  Fedora release 27 (Twenty Seven)
  Fedora release 27 (Twenty Seven)

Some extra places to look into for Ubuntu

1
2
  $ cat /etc/issue.net
  Ubuntu 16.04.3 LTS
1
2
  $ cat /etc/debian_version
  stretch/sid