1

Where can I find a list of different /etc/*release files of various Linux/Unix/MacOS distributions and versions?

Same goes to uname -a command outputs.

Jonas Stein
  • 392
  • 4
  • 13
Vic
  • 95
  • 3
  • 13

3 Answers3

4

Most distributions have a tool called lsb_release.

Gentoo:

$ lsb_release -a
LSB Version:    n/a
Distributor ID: Gentoo
Description:    Gentoo Base System release 2.0.3
Release:    2.0.3
Codename:   n/a

CentOS:

$ lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.7 (Final)
Release:    5.7
Codename:   Final

Other *nix distros: http://linuxmafia.com/faq/Admin/release-files.html

quanta
  • 50,327
  • 19
  • 152
  • 213
4

Not all systems have /etc/*release* files, so if you really want this to be cross-Unix you can't use them.

The POSIX-blessed solution is uname -- If all you need is a coarse OS ID uname -s will probably suffice.
I'm not aware of any canonical list of uname output, but Wikipedia has a table that may be a good starting point (and presumably you have access to the platforms you're trying to detect so you can check what they return).

Sometimes uname doesn't tell the whole story (e.g. Linux distributions, which have substantial variability) - If it's necessary you can figure out more specific information (like "Which Linux distribution?") with a second pass that uses a system-specific tool (like lsb_release on Linux, or oslevel on AIX)

voretaq7
  • 79,345
  • 17
  • 128
  • 213
  • 1
    If you wind up using `uname` as part of your detection process it would be a kindness for the next poor soul who has to do this if you could update that Wikipedia article with the `uname` output from from operating systems which aren't listed :-) – voretaq7 Aug 30 '12 at 16:39
0

Here's an excerpt from a C library I'm writing:

const char* dist = dist_from_os_release();
if (strlen(dist) != 0)
    return dist;
else if (exists("/etc/arch-release"))
    return "arch";
else if (exists("/etc/altlinux-release"))
    return "altlinux";
else if (exists("/etc/angstrom-version"))
    return "angstrom";
else if (exists("/etc/annvix-release"))
    return "annvix";
else if (exists("/etc/arklinux-release"))
    return "arklinux";
else if (exists("/etc/aurox-release"))
    return "aurox";
else if (exists("/etc/blackcat-release"))
    return "blackcat";
else if (exists("/etc/cobalt-release"))
    return "cobalt";
else if (exists("/etc/conectiva-release"))
    return "conectiva";
else if (exists("/etc/debian_version") || exists("/etc/debian_release"))
    return "debian";
else if (exists("/etc/fedora-release"))
    return "fedora";
else if (exists("/etc/eos-version"))
    return "FreeEOS";
else if (exists("/etc/frugalware-release"))
    return "frugalware";
else if (exists("/etc/gentoo-release"))
    return "gentoo";
else if (exists("/etc/hlfs-release") || exists("/etc/hlfs_release"))
    return "HLFS";
else if (exists("/etc/immunix-release"))
    return "immunix";
else if (exists("knoppix_version"))
    return "knoppix";
else if (exists("/etc/lfs-release") || exists("/etc/lfs_version"))
    return "LFS";
else if (exists("/etc/linuxppc-release"))
    return "Linux-PPC";
else if (exists("/etc/mageia-release"))
    return "mageia";
else if (exists("/etc/mandrake-release"))
    return "mandrake";
else if (exists("/etc/mandriva-release") || exists("/etc/mandakelinux-release"))
    return "mandriva";
else if (exists("/etc/meego-release"))
    return "meego";
else if (exists("/etc/mklinux-release"))
    return "MkLinux";
else if (exists("/etc/nld-release"))
    return "Novell Linux Desktop";
else if (exists("/etc/pld-release"))
    return "PLD Linux";
else if (exists("/etc/redhat-release") || exists("/etc/redhat_version"))
    return "RHEL";
else if (exists("/etc/rubix-version"))
    return "rubix";
else if (exists("/etc/slackware-version") || exists("/etc/slackware-release"))
    return "slackware";
else if (exists("/etc/e-smith-release"))
    return "SME Server";
else if (exists("/etc/release"))
    return "Solaris SPARC";
else if (exists("/etc/sun-release"))
    return "Sun JDS";
else if (exists("/etc/SuSE-release") || exists("/etc/novell-release") || exists("/etc/sles-release"))
    return "SuSE";
else if (exists("/etc/synoinfo.conf"))
    return "Synology";
else if (exists("/etc/tinysofa-release"))
    return "tinysofa";
else if (exists("/etc/trustix-release") || exists("/etc/trustix-version"))
    return "trustix";
else if (exists("/etc/turbolinux-release"))
    return "TurboLinux";
else if (exists("/etc/ultrapenguin-release"))
    return "ultrapenguin";
else if (exists("/etc/UnitedLinux-release"))
    return "UnitedLinux";
else if (exists("/etc/va-release"))
    return "VA-Linux/RH-VALE";
else if (exists("/etc/yellowdog-release"))
    return "yellowdog";
else {
    struct utsname unameD;
    uname(&unameD);
    return strlen(unameD.nodename) > 0 ? unameD.nodename : unameD.sysname;
}

https://github.com/offscale/osbuild/commit/49200888e717907bb3dc36021f725b7e668274b7#diff-cc898028570115949c889ad5b8266020R34

Samuel Marks
  • 111
  • 1