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?
The kernel is universally detected with 'uname':
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:
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:
But Debian has /etc/debian_version:
Fedora, Red Hat and CentOS have:
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,
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.
|show 4 more comments|
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.
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.
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?