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.
protected by Diago Dec 20 '10 at 14:27
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.