Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to determine what version (distribution & kernel version, I suppose) of Linux is running (from the command-line), that works on any Linux system?

share|improve this question

6 Answers 6

up vote 113 down vote accepted

The kernel is universally detected with 'uname':

$ uname -or
2.6.18-128.el5 GNU/Linux

There really isn't a cross-distribution way to determine what distribution and version you're on. There are attempts to make this consistent, but it ultimately varies, unfortunately. LSB tools provide this information, but ironically aren't installed by default everywhere. Example on an Ubuntu 9.04 system with the lsb-release package installed:

$ lsb_release -irc
Distributor ID: Ubuntu
Release:        9.04
Codename:       jaunty

Otherwise, the closest widely-available method is checking "/etc/something-release" files. These are common on most of the common platforms, or on their derivatives (ie Red Hat and CentOS).

Here's some examples.

For example, Ubuntu has /etc/lsb-release:

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.04
DISTRIB_CODENAME=jaunty
DISTRIB_DESCRIPTION="Ubuntu 9.04"

But Debian has /etc/debian_version:

cat /etc/debian_version
5.0.2

Fedora, Red Hat and CentOS have:

Fedora: cat /etc/fedora-release
Fedora release 10 (Cambridge)
Red Hat/CentOS: cat /etc/redhat-release
CentOS release 5.3 (Final)

Gentoo:

cat /etc/gentoo-release
Gentoo Base System release 1.12.11.1

I don't have a SUSE system available at the moment, but I believe it is /etc/SuSE-release.

Slackware has /etc/slackware-release.

Mandriva has /etc/mandriva-release.

For most of the popular distributions then,

cat /etc/*{release,version}

Will most often work. Stripped down and barebones "server" installations might not have the 'release' package for the distribution installed.

Additionally, two 3rd party programs you can use to automatically get this information are Ohai and Facter.

Note that many distributions have this kind of information in /etc/issue or /etc/motd, but some security policies and best practices indicate that these files should contain access notification banners.

share|improve this answer
3  
Lol here I was thinking to suggest: look for About! –  Ivo Flipse Jul 22 '09 at 19:40
2  
Slackware has /etc/slackware-version –  Ken Keenan Jul 22 '09 at 19:45
    
Thanks Ken, I don't have a slackware system either. –  jtimberman Jul 22 '09 at 19:56
3  
IOW: ls /etc/*{release,version} and examine whatever comes back... –  freiheit Jul 22 '09 at 20:11
1  
Most also have /etc/issue –  Drew Stephens Jul 23 '09 at 6:42

You could also try:

$ cat /etc/issue

It usually (not always, though) will tell you what distribution you are using. /etc/issue is the file used for login screen.

share|improve this answer
2  
This is the only one that nailed it for me on a shared Media Temple server. Thanks!! –  TryTryAgain Feb 8 '13 at 18:03

Kernel: uname -a

share|improve this answer
    
+1. For similar systems, like MinGW, the "-a" is required to get the version information, for example, "MINGW32_NT-5.1 LAP065 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys". –  Peter Mortensen May 2 '12 at 8:39

lsb_release -a, when available, is useful.

share|improve this answer

cat /etc/os-release

at a minimum for Ubuntu and OpenSUSE.

Does not work for OS-X at least until 10.9 (Mavericks) Use *sw_vers* instead

OpenSUSE has cat /etc/SuSE-release up until 13.1 but is deprecated in favour of os-release.

share|improve this answer

cat /proc/version found me Red Hat on a shared VPS.

share|improve this answer

protected by Diago Dec 20 '10 at 14:27

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.