Determining WHICH *nix distro is currently used…

Originally, I had run into the issue of trying to determine the *nix distribution – a command that would tell me the distribution and the build and everythign else I wanted to know. After reviewing some of the awesome comments left behind, here’s the updated perl script to determine the distribution (in Perl).

#!/usr/bin/env perl
use strict;
use warnings;

my ( $distro );
$distro = `lsb_release -i -s`;
chomp $distro;

my %installCmd = (
"Fedora" => \&fedora,
"Ubuntu" => \&ubuntu,


sub test {
if ( exists $installCmd{$distro} ) {
} else {
print "Supported Distributions are: ". join(', ' , keys %installCmd) . ".\n";

sub fedora { print "Hello from the Fedora Family!"; }
sub ubuntu { print "Hello from UBUNTU!!!"; }


18 thoughts on “Determining WHICH *nix distro is currently used…

  1. Jay Scott Raymond says:

    Determining distro:


    cat /etc/issue

    • /etc/issue is typically the banner for ssh logins, and some people may find a need to change that banner to either a) mask what os they’re running or b) write a disclaimer or something for those logging into the system.

      falls under UserError, imo.

  2. Christian says:

    uname -v does display ‘Ubuntu’ as part of the kernel version. What about Fedora?

  3. cHagHi says:

    Try parsing the contents of /etc/lsb-release

  4. etank says:

    lsb_release -a

    On a Fedora box would give you something like this:

    LSB Version: :core-3.1-ia32:core-3.1-noarch:core-3.2-ia32:core-3.2-noarch:desktop-3.1-ia32:desktop-3.1-noarch:desktop-3.2-ia32:desktop-3.2-noarch
    Distributor ID: Fedora
    Description: Fedora release 12 (Constantine)
    Release: 12
    Codename: Constantine

    The same command will work on Ubuntu / Debian too.

  5. etank says:

    On Fedora if you do:

    uname -a

    You get something like:

    Linux carter #1 SMP Fri Dec 4 00:43:59 EST 2009 i686 i686 i386 GNU/Linux

    Notice the fc12 in the string. That means I am running Fedora 12.

    • ya, i’m not looking for the fc12 or anything like that…I want something that will be uniform throughout, across all platforms of linux (preferably).

      will the lsb_release -a work with slax, mandrake, gentoo and other distros as well?

      • NoOne says:

        It should. -a gives you everything though, for just the distributor, you want -i (see man page for other options)

  6. Julien says:

    Facter will give you a lot of informations, you need facter anyway if you use puppet… you use puppet, right ?

  7. Julien says:

    Give it a shot, especially with what you’re trying to achieve (modular, cross distribution setup/config management).

    Example run here :

    Facter :
    Puppet :

  8. agfitzp says:

    Use the -s flag to get the short answer:

    alex@dv9000-ubuntu:~$ lsb_release -i -s

  9. Rajasun says:

    For Ubuntu,
    cat /proc/version
    and of course
    cat /etc/lsb-release

    And cat /etc/debian_version though this may kinda confused some :P

  10. Azrael says:

    “cat /etc/*release” should work on most Linux distros and will work on most Unixes.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s