Monday, September 8, 2008

Determining Linux Version

Linux distributions don't tend to standardize where they store information about what release is installed. Going further, there's not even a standard way to detect what distribution is installed. If a system is running a popular distro, this information can usually be found in one of the following files:

Debian /etc/debian_release, /etc/debian_version,
Fedora /etc/fedora-release
Gentoo /etc/gentoo-release
Mandrake /etc/mandrake-release
Novell SUSE /etc/SUSE-release
Red Hat /etc/redhat-release, /etc/redhat_version
Slackware /etc/slackware-release, /etc/slackware-version
Solaris/Sparc /etc/release
Sun JDS /etc/sun-release
Ubuntu /etc/lsb-release
UnitedLinux /etc/UnitedLinux-release
Yellow dog /etc/yellowdog-release

You can find more information on this problem as well as a shell script to assist with OS detection here. An even larger master list can be found here.


Steve Laniel said...

You may already know this, but the non-portability of version information is one of the problems that the Linux Standard Base is trying to solve. Hence the 'lsb-release' file in one of your listed distributions.

Anonymous said...

what about `cat /etc/issue`? I've only tested CentOS, REHL and Ubuntu. Does anybody else know if its supported by the other major distros?

canbican said...

lsb-release is around for maybe ages, yet only a few distributions contain this file. So, relying on lsb-relase is itsef non-portable :)

Pento said...

Usually I watch /et/issue

egypt said...

/etc/issue is used for sshd's banner, so a lot of systems will alter it. `cat /etc/*release' is fairly reliable in my experience.