How to check OS and version in Linux
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).
$ uname -aLinux 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$ uname -aLinux 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/LinuxDistribution 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.
$ lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 16.04.3 LTSRelease: 16.04Codename: xenialOn Fedora you may need to install lsb_release.
$ sudo yum install lsb_release -a$ lsb_release -aLSB 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-noarchDistributor ID: FedoraDescription: Fedora release 27 (Twenty Seven)Release: 27Codename: TwentySevenRelease files
Ubuntu has two release files /etc/lsb-release and /etc/os-release
$ cat /etc/*-releaseDISTRIB_ID=UbuntuDISTRIB_RELEASE=16.04DISTRIB_CODENAME=xenialDISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"NAME="Ubuntu"VERSION="16.04.3 LTS (Xenial Xerus)"ID=ubuntuID_LIKE=debianPRETTY_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=xenialUBUNTU_CODENAME=xenialFedoro has /etc/fedora-release, /etc/os-release, /etc/redhat-release, /etc/system-release
$ cat /etc/*-release sudo cat /etc/*releaseFedora release 27 (Twenty Seven)NAME=FedoraVERSION="27 (Cloud Edition)"ID=fedoraVERSION_ID=27PRETTY_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=27REDHAT_SUPPORT_PRODUCT="Fedora"REDHAT_SUPPORT_PRODUCT_VERSION=27PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"VARIANT="Cloud Edition"VARIANT_ID=cloudFedora release 27 (Twenty Seven)Fedora release 27 (Twenty Seven)Some extra places to look into for Ubuntu
$ cat /etc/issue.netUbuntu 16.04.3 LTS$ cat /etc/debian_versionstretch/sid