How do I find out what version of Linux is running?How can you find out which linux distribution you are currently using, from the shell?Get the distro and version of serversHow do i find out which Fedora version I'm running from the cli (not uname -a)?Can I trust that every Debian-derived distro will have a 'base-files' package that contains '/etc/debian_version'?Can I nohup/screen an already-started process?How can you find out which linux distribution you are currently using, from the shell?What version of RHEL am I using?How to install a Linux application in cases when parallel startup scripts running is enabled or disabled?How to find out PCI version information in linuxKeeping a linux process running after I logoutLinux + how to verify linux version 32 Bit or 64 BitWhat permissions should my website files/folders have on a Linux webserver?How to find out the virtualization type of an linux VPS?how to check linux mint or ubuntu debian version

How does the +1 Keen Composite Longbow (+2 Str) work?

Is presenting a play showing Military characters in a bad light a crime in the US?

Presenting 2 results for one variable using a left brace

How to tease a romance without a cat and mouse chase?

How to choose the correct exposure for flower photography?

How did Jean Parisot de Valette, 49th Grand Master of the Order of Malta, die?

Can ROS workspace safely exist in an external HDD?

How to play vs. 1.e4 e5 2.Nf3 Nc6 3.Bc4 d6?

Existence of a model of ZFC in which the natural numbers are really the natural numbers

Vehemently against code formatting

What's is the easiest way to purchase a stock and hold it

Is there a realtime, uncut video of Saturn V ignition through tower clear?

How did Arya and the Hound get into King's Landing so easily?

Does George B Sperry logo on fold case for photos indicate photographer or case manufacturer?

What does it mean for a program to be 32 or 64 bit?

Farthing / Riding

Was murdering a slave illegal in American slavery, and if so, what punishments were given for it?

400–430 degrees Celsius heated bath

Is my company merging branches wrong?

Are there historical examples of audiences drawn to a work that was "so bad it's good"?

Why does an injection from a set to a countable set imply that set is countable?

Keeping the dodos out of the field

Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario?

How to say "they didn't leave him a penny"?



How do I find out what version of Linux is running?


How can you find out which linux distribution you are currently using, from the shell?Get the distro and version of serversHow do i find out which Fedora version I'm running from the cli (not uname -a)?Can I trust that every Debian-derived distro will have a 'base-files' package that contains '/etc/debian_version'?Can I nohup/screen an already-started process?How can you find out which linux distribution you are currently using, from the shell?What version of RHEL am I using?How to install a Linux application in cases when parallel startup scripts running is enabled or disabled?How to find out PCI version information in linuxKeeping a linux process running after I logoutLinux + how to verify linux version 32 Bit or 64 BitWhat permissions should my website files/folders have on a Linux webserver?How to find out the virtualization type of an linux VPS?how to check linux mint or ubuntu debian version






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








29















Sometimes your scripts need to behave differently on different Linux's. How can I determine which version of Linux a script is running on?










share|improve this question

















  • 1





    By version, do you mean the kernel version? What distribution? The distro version?

    – Chris Upchurch
    May 2 '09 at 23:14






  • 2





    I'm sure jldugger wants to find out which distribution family the system is running. It's unlikely a script would be affected by the kernel version unless it depends on some /sys or /proc stuff - and even then it's usually easier to assume based on distribution than on kernel.

    – Mihai Limbăşan
    May 2 '09 at 23:18

















29















Sometimes your scripts need to behave differently on different Linux's. How can I determine which version of Linux a script is running on?










share|improve this question

















  • 1





    By version, do you mean the kernel version? What distribution? The distro version?

    – Chris Upchurch
    May 2 '09 at 23:14






  • 2





    I'm sure jldugger wants to find out which distribution family the system is running. It's unlikely a script would be affected by the kernel version unless it depends on some /sys or /proc stuff - and even then it's usually easier to assume based on distribution than on kernel.

    – Mihai Limbăşan
    May 2 '09 at 23:18













29












29








29


12






Sometimes your scripts need to behave differently on different Linux's. How can I determine which version of Linux a script is running on?










share|improve this question














Sometimes your scripts need to behave differently on different Linux's. How can I determine which version of Linux a script is running on?







linux scripting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 2 '09 at 23:11









jlduggerjldugger

9,4061866120




9,4061866120







  • 1





    By version, do you mean the kernel version? What distribution? The distro version?

    – Chris Upchurch
    May 2 '09 at 23:14






  • 2





    I'm sure jldugger wants to find out which distribution family the system is running. It's unlikely a script would be affected by the kernel version unless it depends on some /sys or /proc stuff - and even then it's usually easier to assume based on distribution than on kernel.

    – Mihai Limbăşan
    May 2 '09 at 23:18












  • 1





    By version, do you mean the kernel version? What distribution? The distro version?

    – Chris Upchurch
    May 2 '09 at 23:14






  • 2





    I'm sure jldugger wants to find out which distribution family the system is running. It's unlikely a script would be affected by the kernel version unless it depends on some /sys or /proc stuff - and even then it's usually easier to assume based on distribution than on kernel.

    – Mihai Limbăşan
    May 2 '09 at 23:18







1




1





By version, do you mean the kernel version? What distribution? The distro version?

– Chris Upchurch
May 2 '09 at 23:14





By version, do you mean the kernel version? What distribution? The distro version?

– Chris Upchurch
May 2 '09 at 23:14




2




2





I'm sure jldugger wants to find out which distribution family the system is running. It's unlikely a script would be affected by the kernel version unless it depends on some /sys or /proc stuff - and even then it's usually easier to assume based on distribution than on kernel.

– Mihai Limbăşan
May 2 '09 at 23:18





I'm sure jldugger wants to find out which distribution family the system is running. It's unlikely a script would be affected by the kernel version unless it depends on some /sys or /proc stuff - and even then it's usually easier to assume based on distribution than on kernel.

– Mihai Limbăşan
May 2 '09 at 23:18










14 Answers
14






active

oldest

votes


















27














Don't try and make assumptions based on the distro as to what you can and cannot do, for that way lies madness (see also "User Agent detection"). Instead, detect whether what it is that you want to do is supported, and how it's done by whatever command or file location you want to use.



For example, if you wanted to install a package, you can detect whether you're on a Debian-like system or a RedHat-like system by checking for the existence of dpkg or rpm (check for dpkg first, because Debian machines can have the rpm command on them...). Make your decision as to what to do based on that, not just on whether it's a Debian or RedHat system. That way you'll automatically support any derivative distros that you didn't explicitly program in. Oh, and if your package requires specific dependencies, then test for those too and let the user know what they're missing.



Another example is fiddling with network interfaces. Work out what to do based on whether there's an /etc/network/interfaces file or an /etc/sysconfig/network-scripts directory, and go from there.



Yes, it's more work, but unless you want to remake all the mistakes that web developers have made over the past decade or more, you'll do it the smart way right from the start.






share|improve this answer


















  • 1





    (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

    – Nicholas Wilson
    May 22 '13 at 9:55


















36














There is no cross-distribution way. However:




  • Redhat and friends: Test for /etc/redhat-release, check contents

  • Debian: Test for /etc/debian_version, check contents

  • Mandriva and friends: Test for /etc/version, check contents

  • Slackware: Test for /etc/slackware-version, check contents



Etc. Generally speaking, check for /etc/*-release and /etc/*-version.




Edit: Found an old (1+ years) bash script of mine lying around that I must have cobbled together over the years (it has an impressive CVS log going back 6 years.) It might not work properly anymore as-is and I can't be bothered to find installed distros to test against, but it should provide you with a good starting point. It works fine on CentOS, Fedora and Gentoo. gyaresu tested it successfully on Debian Lenny.



#!/bin/bash

get_distribution_type()

local dtype
# Assume unknown
dtype="unknown"

# First test against Fedora / RHEL / CentOS / generic Redhat derivative
if [ -r /etc/rc.d/init.d/functions ]; then
source /etc/rc.d/init.d/functions
[ zz`type -t passed 2>/dev/null` == "zzfunction" ] && dtype="redhat"

# Then test against SUSE (must be after Redhat,
# I've seen rc.status on Ubuntu I think? TODO: Recheck that)
elif [ -r /etc/rc.status ]; then
source /etc/rc.status
[ zz`type -t rc_reset 2>/dev/null` == "zzfunction" ] && dtype="suse"

# Then test against Debian, Ubuntu and friends
elif [ -r /lib/lsb/init-functions ]; then
source /lib/lsb/init-functions
[ zz`type -t log_begin_msg 2>/dev/null` == "zzfunction" ] && dtype="debian"

# Then test against Gentoo
elif [ -r /etc/init.d/functions.sh ]; then
source /etc/init.d/functions.sh
[ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && dtype="gentoo"

# For Slackware we currently just test if /etc/slackware-version exists
# and isn't empty (TODO: Find a better way :)
elif [ -s /etc/slackware-version ]; then
dtype="slackware"
fi
echo $dtype



Note that this will probably only work correctly in Bash. You could rewrite it for other shells.



That being said, you might want to test for features, not for distributions. I'm not using this anymore simply because it became a maintenance burden. It's easier to rely on cross-distribution tools and solutions.




Conceptually, what it does is, in order:




  • Pull in a known, "common init script function" type of file. Those are distribution-specific. If it doesn't exist, skip to next distribution check.

  • Check the existence of a specific, known-to-exist, often-used and unlikely to be renamed function from that core script. We do that using the type Bash builtin. type -t returns function if that symbol is a function. We prepend zz to the output from type -t 2>/dev/null because if the name isn't defined the output string would be empty and we'd get a syntax error about a missing left hand to the == operator. If the name we just checked isn't a function, skip to next distribution check, otherwise we found the distribution type.

  • Finally, echo the distribution type so the function output can be easily used in a case .. esac block.




Edit in case you're trying to run this as a straight script: This script is supposed to get sourced or included from other scripts. It does not output anything on its own if you run it as-is. To test it, source it and then invoke the function, e.g.:



source /path/to/this/script.sh
get_distribution_type


at the bash prompt.




Edit: Please note that this script does not require root privileges. I urge you not to run it as root. Shouldn't harm anything, but there's no need.




Found a link to a relevant mailing list post in the CVS log. Should be useful in unwrapping init script spaghetti.






share|improve this answer

























  • I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

    – Gareth
    May 3 '09 at 0:39











  • gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

    – Mihai Limbăşan
    May 3 '09 at 0:51











  • @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

    – Mihai Limbăşan
    May 3 '09 at 1:20











  • @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

    – Gareth
    May 3 '09 at 6:33











  • @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

    – Mihai Limbăşan
    May 3 '09 at 7:24


















17














You can find the kernel version by running uname -a, finding the distro version is dependant on the distro.



On Ubuntu and some other OS' you can run lsb_release -a or read /etc/lsb_release



Debian stores the version in /etc/debian_version






share|improve this answer























  • +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

    – Josh Kelley
    Jun 10 '09 at 10:52











  • for just the description 'lsb_release -ds'.

    – flickerfly
    Sep 12 '14 at 16:12


















6














Most distro's have a unique method of determining the particular distribution.



For example:



Redhat (And derivatives): /etc/redhat-release

SUSE: /etc/SUSE-release


There is a standard out there known as the Linux Standard Base or LSB.
It defines that there should be a file called /etc/lsb-release or a program called lsb_release that will echo back information about your linux distro.



lsb_release -a





share|improve this answer























  • And of course, lsb_release does not exist on CentOS 6.

    – Justin
    Sep 21 '12 at 2:45


















6














python -c 'import platform ; print platform.dist()[0]'


code:
http://hg.python.org/cpython/file/2.7/Lib/platform.py






share|improve this answer

























  • Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

    – heinrich5991
    Dec 9 '12 at 14:11


















5














In addition to the other answers: If you just want to parse one file, most distros personalize the tty login via /etc/issue e.g.:




Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel r (l).




And yes I know it's suboptimal. :)






share|improve this answer























  • It may be sub-optimal, but it is in the same place.

    – Brad Gilbert
    May 3 '09 at 3:17


















4














facter is a handy tool for this sort of discovery, although it probably uses some of the methods detailed above, and requires Ruby.






share|improve this answer






























    2














    All you need to do is type uname -a at your favorite shell. That will print out the kernel name and version.






    share|improve this answer






























      2














      I've found that cat /etc/*release* almost always works.






      share|improve this answer






























        2














        I concur with Mark, Adam and Mihai (can't vote up due to insufficient reputation). Solutions based on LSB and its relative FHS will work with most distributions and are likely to continue working in future. LSB and FHS are your friends.






        share|improve this answer






























          2














          You can also get the version by



          cat /proc/version


          o/p:




          Linux version 2.6.17-13mdv (rtp@octopus.mandriva.com) (gcc version
          4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)) #1 SMP Fri Mar 23 19:03:31 UTC 2007







          share|improve this answer
































            1














            The version of linux is a hard question. If we look at it narrowly we have the kernel version you can get with "uname -r". Distribution version is mostly irrellevant. Some distributions are better (enterprise distributions such as Redhat Enterprise Linux). Other distributions like Gentoo are basically moving targets that have no sensible version at all.
            If you need to do things based on version, take a look at major components that are relevant to you:



            Component Version command
            glibc /lib/libc.so.6
            gcc gcc --version
            X xdpyinfo
            libX11 pkg-config --modversion x11
            gtk+ pkg-config --modversion gtk+-2.0
            qt-4 pkg-config --modversion QtCore

            etc...





            share|improve this answer






























              1














              You can also check the Grub menu, usually gives you a bunch of distro/version info :-)






              share|improve this answer






























                -1














                FusionInventory is a cross-platform lightweight inventory tool that can get this information on many Linux distros but also on BSDs, Windows, MacOS X and other unices.



                If available, they use lsb_release (as mentioned a few times above), but if not they have a very useful list of files and regular expressions to check the distro name and version: https://github.com/fusinv/fusioninventory-agent/blob/2.2.x/lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Distro/NonLSB.pm#L16.



                I would recommend using FusionInventory itself to get this information, rather than reimplementing your own scripts with this logic, as their community will maintain this functionality up to date. You could either use the agent on it's own (it outputs a XML/JSON file which is easy to parse) or couple it with a wider solution to manage the machines in your network like GLPI or Rudder, depending on your needs.






                share|improve this answer























                • This would be a good solution if it didn't have external dependencies of Perl modules

                  – Will Sheppard
                  Jan 8 '16 at 13:53












                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "2"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f3331%2fhow-do-i-find-out-what-version-of-linux-is-running%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                14 Answers
                14






                active

                oldest

                votes








                14 Answers
                14






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                27














                Don't try and make assumptions based on the distro as to what you can and cannot do, for that way lies madness (see also "User Agent detection"). Instead, detect whether what it is that you want to do is supported, and how it's done by whatever command or file location you want to use.



                For example, if you wanted to install a package, you can detect whether you're on a Debian-like system or a RedHat-like system by checking for the existence of dpkg or rpm (check for dpkg first, because Debian machines can have the rpm command on them...). Make your decision as to what to do based on that, not just on whether it's a Debian or RedHat system. That way you'll automatically support any derivative distros that you didn't explicitly program in. Oh, and if your package requires specific dependencies, then test for those too and let the user know what they're missing.



                Another example is fiddling with network interfaces. Work out what to do based on whether there's an /etc/network/interfaces file or an /etc/sysconfig/network-scripts directory, and go from there.



                Yes, it's more work, but unless you want to remake all the mistakes that web developers have made over the past decade or more, you'll do it the smart way right from the start.






                share|improve this answer


















                • 1





                  (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

                  – Nicholas Wilson
                  May 22 '13 at 9:55















                27














                Don't try and make assumptions based on the distro as to what you can and cannot do, for that way lies madness (see also "User Agent detection"). Instead, detect whether what it is that you want to do is supported, and how it's done by whatever command or file location you want to use.



                For example, if you wanted to install a package, you can detect whether you're on a Debian-like system or a RedHat-like system by checking for the existence of dpkg or rpm (check for dpkg first, because Debian machines can have the rpm command on them...). Make your decision as to what to do based on that, not just on whether it's a Debian or RedHat system. That way you'll automatically support any derivative distros that you didn't explicitly program in. Oh, and if your package requires specific dependencies, then test for those too and let the user know what they're missing.



                Another example is fiddling with network interfaces. Work out what to do based on whether there's an /etc/network/interfaces file or an /etc/sysconfig/network-scripts directory, and go from there.



                Yes, it's more work, but unless you want to remake all the mistakes that web developers have made over the past decade or more, you'll do it the smart way right from the start.






                share|improve this answer


















                • 1





                  (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

                  – Nicholas Wilson
                  May 22 '13 at 9:55













                27












                27








                27







                Don't try and make assumptions based on the distro as to what you can and cannot do, for that way lies madness (see also "User Agent detection"). Instead, detect whether what it is that you want to do is supported, and how it's done by whatever command or file location you want to use.



                For example, if you wanted to install a package, you can detect whether you're on a Debian-like system or a RedHat-like system by checking for the existence of dpkg or rpm (check for dpkg first, because Debian machines can have the rpm command on them...). Make your decision as to what to do based on that, not just on whether it's a Debian or RedHat system. That way you'll automatically support any derivative distros that you didn't explicitly program in. Oh, and if your package requires specific dependencies, then test for those too and let the user know what they're missing.



                Another example is fiddling with network interfaces. Work out what to do based on whether there's an /etc/network/interfaces file or an /etc/sysconfig/network-scripts directory, and go from there.



                Yes, it's more work, but unless you want to remake all the mistakes that web developers have made over the past decade or more, you'll do it the smart way right from the start.






                share|improve this answer













                Don't try and make assumptions based on the distro as to what you can and cannot do, for that way lies madness (see also "User Agent detection"). Instead, detect whether what it is that you want to do is supported, and how it's done by whatever command or file location you want to use.



                For example, if you wanted to install a package, you can detect whether you're on a Debian-like system or a RedHat-like system by checking for the existence of dpkg or rpm (check for dpkg first, because Debian machines can have the rpm command on them...). Make your decision as to what to do based on that, not just on whether it's a Debian or RedHat system. That way you'll automatically support any derivative distros that you didn't explicitly program in. Oh, and if your package requires specific dependencies, then test for those too and let the user know what they're missing.



                Another example is fiddling with network interfaces. Work out what to do based on whether there's an /etc/network/interfaces file or an /etc/sysconfig/network-scripts directory, and go from there.



                Yes, it's more work, but unless you want to remake all the mistakes that web developers have made over the past decade or more, you'll do it the smart way right from the start.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 3 '09 at 0:06









                womblewomble

                86.3k18147205




                86.3k18147205







                • 1





                  (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

                  – Nicholas Wilson
                  May 22 '13 at 9:55












                • 1





                  (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

                  – Nicholas Wilson
                  May 22 '13 at 9:55







                1




                1





                (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

                – Nicholas Wilson
                May 22 '13 at 9:55





                (Expanding on this answer) Feature-detection is preferable in some situations, but make sure you never try and guess the distribution from the features you detect! Don't misread the answer and work out whether the platform is RedHat based on what files are in /etc. If you really do need the distribution name, check lsb_release (or /etc/redhat-release, and so on).

                – Nicholas Wilson
                May 22 '13 at 9:55













                36














                There is no cross-distribution way. However:




                • Redhat and friends: Test for /etc/redhat-release, check contents

                • Debian: Test for /etc/debian_version, check contents

                • Mandriva and friends: Test for /etc/version, check contents

                • Slackware: Test for /etc/slackware-version, check contents



                Etc. Generally speaking, check for /etc/*-release and /etc/*-version.




                Edit: Found an old (1+ years) bash script of mine lying around that I must have cobbled together over the years (it has an impressive CVS log going back 6 years.) It might not work properly anymore as-is and I can't be bothered to find installed distros to test against, but it should provide you with a good starting point. It works fine on CentOS, Fedora and Gentoo. gyaresu tested it successfully on Debian Lenny.



                #!/bin/bash

                get_distribution_type()

                local dtype
                # Assume unknown
                dtype="unknown"

                # First test against Fedora / RHEL / CentOS / generic Redhat derivative
                if [ -r /etc/rc.d/init.d/functions ]; then
                source /etc/rc.d/init.d/functions
                [ zz`type -t passed 2>/dev/null` == "zzfunction" ] && dtype="redhat"

                # Then test against SUSE (must be after Redhat,
                # I've seen rc.status on Ubuntu I think? TODO: Recheck that)
                elif [ -r /etc/rc.status ]; then
                source /etc/rc.status
                [ zz`type -t rc_reset 2>/dev/null` == "zzfunction" ] && dtype="suse"

                # Then test against Debian, Ubuntu and friends
                elif [ -r /lib/lsb/init-functions ]; then
                source /lib/lsb/init-functions
                [ zz`type -t log_begin_msg 2>/dev/null` == "zzfunction" ] && dtype="debian"

                # Then test against Gentoo
                elif [ -r /etc/init.d/functions.sh ]; then
                source /etc/init.d/functions.sh
                [ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && dtype="gentoo"

                # For Slackware we currently just test if /etc/slackware-version exists
                # and isn't empty (TODO: Find a better way :)
                elif [ -s /etc/slackware-version ]; then
                dtype="slackware"
                fi
                echo $dtype



                Note that this will probably only work correctly in Bash. You could rewrite it for other shells.



                That being said, you might want to test for features, not for distributions. I'm not using this anymore simply because it became a maintenance burden. It's easier to rely on cross-distribution tools and solutions.




                Conceptually, what it does is, in order:




                • Pull in a known, "common init script function" type of file. Those are distribution-specific. If it doesn't exist, skip to next distribution check.

                • Check the existence of a specific, known-to-exist, often-used and unlikely to be renamed function from that core script. We do that using the type Bash builtin. type -t returns function if that symbol is a function. We prepend zz to the output from type -t 2>/dev/null because if the name isn't defined the output string would be empty and we'd get a syntax error about a missing left hand to the == operator. If the name we just checked isn't a function, skip to next distribution check, otherwise we found the distribution type.

                • Finally, echo the distribution type so the function output can be easily used in a case .. esac block.




                Edit in case you're trying to run this as a straight script: This script is supposed to get sourced or included from other scripts. It does not output anything on its own if you run it as-is. To test it, source it and then invoke the function, e.g.:



                source /path/to/this/script.sh
                get_distribution_type


                at the bash prompt.




                Edit: Please note that this script does not require root privileges. I urge you not to run it as root. Shouldn't harm anything, but there's no need.




                Found a link to a relevant mailing list post in the CVS log. Should be useful in unwrapping init script spaghetti.






                share|improve this answer

























                • I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

                  – Gareth
                  May 3 '09 at 0:39











                • gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

                  – Mihai Limbăşan
                  May 3 '09 at 0:51











                • @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

                  – Mihai Limbăşan
                  May 3 '09 at 1:20











                • @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

                  – Gareth
                  May 3 '09 at 6:33











                • @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

                  – Mihai Limbăşan
                  May 3 '09 at 7:24















                36














                There is no cross-distribution way. However:




                • Redhat and friends: Test for /etc/redhat-release, check contents

                • Debian: Test for /etc/debian_version, check contents

                • Mandriva and friends: Test for /etc/version, check contents

                • Slackware: Test for /etc/slackware-version, check contents



                Etc. Generally speaking, check for /etc/*-release and /etc/*-version.




                Edit: Found an old (1+ years) bash script of mine lying around that I must have cobbled together over the years (it has an impressive CVS log going back 6 years.) It might not work properly anymore as-is and I can't be bothered to find installed distros to test against, but it should provide you with a good starting point. It works fine on CentOS, Fedora and Gentoo. gyaresu tested it successfully on Debian Lenny.



                #!/bin/bash

                get_distribution_type()

                local dtype
                # Assume unknown
                dtype="unknown"

                # First test against Fedora / RHEL / CentOS / generic Redhat derivative
                if [ -r /etc/rc.d/init.d/functions ]; then
                source /etc/rc.d/init.d/functions
                [ zz`type -t passed 2>/dev/null` == "zzfunction" ] && dtype="redhat"

                # Then test against SUSE (must be after Redhat,
                # I've seen rc.status on Ubuntu I think? TODO: Recheck that)
                elif [ -r /etc/rc.status ]; then
                source /etc/rc.status
                [ zz`type -t rc_reset 2>/dev/null` == "zzfunction" ] && dtype="suse"

                # Then test against Debian, Ubuntu and friends
                elif [ -r /lib/lsb/init-functions ]; then
                source /lib/lsb/init-functions
                [ zz`type -t log_begin_msg 2>/dev/null` == "zzfunction" ] && dtype="debian"

                # Then test against Gentoo
                elif [ -r /etc/init.d/functions.sh ]; then
                source /etc/init.d/functions.sh
                [ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && dtype="gentoo"

                # For Slackware we currently just test if /etc/slackware-version exists
                # and isn't empty (TODO: Find a better way :)
                elif [ -s /etc/slackware-version ]; then
                dtype="slackware"
                fi
                echo $dtype



                Note that this will probably only work correctly in Bash. You could rewrite it for other shells.



                That being said, you might want to test for features, not for distributions. I'm not using this anymore simply because it became a maintenance burden. It's easier to rely on cross-distribution tools and solutions.




                Conceptually, what it does is, in order:




                • Pull in a known, "common init script function" type of file. Those are distribution-specific. If it doesn't exist, skip to next distribution check.

                • Check the existence of a specific, known-to-exist, often-used and unlikely to be renamed function from that core script. We do that using the type Bash builtin. type -t returns function if that symbol is a function. We prepend zz to the output from type -t 2>/dev/null because if the name isn't defined the output string would be empty and we'd get a syntax error about a missing left hand to the == operator. If the name we just checked isn't a function, skip to next distribution check, otherwise we found the distribution type.

                • Finally, echo the distribution type so the function output can be easily used in a case .. esac block.




                Edit in case you're trying to run this as a straight script: This script is supposed to get sourced or included from other scripts. It does not output anything on its own if you run it as-is. To test it, source it and then invoke the function, e.g.:



                source /path/to/this/script.sh
                get_distribution_type


                at the bash prompt.




                Edit: Please note that this script does not require root privileges. I urge you not to run it as root. Shouldn't harm anything, but there's no need.




                Found a link to a relevant mailing list post in the CVS log. Should be useful in unwrapping init script spaghetti.






                share|improve this answer

























                • I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

                  – Gareth
                  May 3 '09 at 0:39











                • gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

                  – Mihai Limbăşan
                  May 3 '09 at 0:51











                • @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

                  – Mihai Limbăşan
                  May 3 '09 at 1:20











                • @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

                  – Gareth
                  May 3 '09 at 6:33











                • @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

                  – Mihai Limbăşan
                  May 3 '09 at 7:24













                36












                36








                36







                There is no cross-distribution way. However:




                • Redhat and friends: Test for /etc/redhat-release, check contents

                • Debian: Test for /etc/debian_version, check contents

                • Mandriva and friends: Test for /etc/version, check contents

                • Slackware: Test for /etc/slackware-version, check contents



                Etc. Generally speaking, check for /etc/*-release and /etc/*-version.




                Edit: Found an old (1+ years) bash script of mine lying around that I must have cobbled together over the years (it has an impressive CVS log going back 6 years.) It might not work properly anymore as-is and I can't be bothered to find installed distros to test against, but it should provide you with a good starting point. It works fine on CentOS, Fedora and Gentoo. gyaresu tested it successfully on Debian Lenny.



                #!/bin/bash

                get_distribution_type()

                local dtype
                # Assume unknown
                dtype="unknown"

                # First test against Fedora / RHEL / CentOS / generic Redhat derivative
                if [ -r /etc/rc.d/init.d/functions ]; then
                source /etc/rc.d/init.d/functions
                [ zz`type -t passed 2>/dev/null` == "zzfunction" ] && dtype="redhat"

                # Then test against SUSE (must be after Redhat,
                # I've seen rc.status on Ubuntu I think? TODO: Recheck that)
                elif [ -r /etc/rc.status ]; then
                source /etc/rc.status
                [ zz`type -t rc_reset 2>/dev/null` == "zzfunction" ] && dtype="suse"

                # Then test against Debian, Ubuntu and friends
                elif [ -r /lib/lsb/init-functions ]; then
                source /lib/lsb/init-functions
                [ zz`type -t log_begin_msg 2>/dev/null` == "zzfunction" ] && dtype="debian"

                # Then test against Gentoo
                elif [ -r /etc/init.d/functions.sh ]; then
                source /etc/init.d/functions.sh
                [ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && dtype="gentoo"

                # For Slackware we currently just test if /etc/slackware-version exists
                # and isn't empty (TODO: Find a better way :)
                elif [ -s /etc/slackware-version ]; then
                dtype="slackware"
                fi
                echo $dtype



                Note that this will probably only work correctly in Bash. You could rewrite it for other shells.



                That being said, you might want to test for features, not for distributions. I'm not using this anymore simply because it became a maintenance burden. It's easier to rely on cross-distribution tools and solutions.




                Conceptually, what it does is, in order:




                • Pull in a known, "common init script function" type of file. Those are distribution-specific. If it doesn't exist, skip to next distribution check.

                • Check the existence of a specific, known-to-exist, often-used and unlikely to be renamed function from that core script. We do that using the type Bash builtin. type -t returns function if that symbol is a function. We prepend zz to the output from type -t 2>/dev/null because if the name isn't defined the output string would be empty and we'd get a syntax error about a missing left hand to the == operator. If the name we just checked isn't a function, skip to next distribution check, otherwise we found the distribution type.

                • Finally, echo the distribution type so the function output can be easily used in a case .. esac block.




                Edit in case you're trying to run this as a straight script: This script is supposed to get sourced or included from other scripts. It does not output anything on its own if you run it as-is. To test it, source it and then invoke the function, e.g.:



                source /path/to/this/script.sh
                get_distribution_type


                at the bash prompt.




                Edit: Please note that this script does not require root privileges. I urge you not to run it as root. Shouldn't harm anything, but there's no need.




                Found a link to a relevant mailing list post in the CVS log. Should be useful in unwrapping init script spaghetti.






                share|improve this answer















                There is no cross-distribution way. However:




                • Redhat and friends: Test for /etc/redhat-release, check contents

                • Debian: Test for /etc/debian_version, check contents

                • Mandriva and friends: Test for /etc/version, check contents

                • Slackware: Test for /etc/slackware-version, check contents



                Etc. Generally speaking, check for /etc/*-release and /etc/*-version.




                Edit: Found an old (1+ years) bash script of mine lying around that I must have cobbled together over the years (it has an impressive CVS log going back 6 years.) It might not work properly anymore as-is and I can't be bothered to find installed distros to test against, but it should provide you with a good starting point. It works fine on CentOS, Fedora and Gentoo. gyaresu tested it successfully on Debian Lenny.



                #!/bin/bash

                get_distribution_type()

                local dtype
                # Assume unknown
                dtype="unknown"

                # First test against Fedora / RHEL / CentOS / generic Redhat derivative
                if [ -r /etc/rc.d/init.d/functions ]; then
                source /etc/rc.d/init.d/functions
                [ zz`type -t passed 2>/dev/null` == "zzfunction" ] && dtype="redhat"

                # Then test against SUSE (must be after Redhat,
                # I've seen rc.status on Ubuntu I think? TODO: Recheck that)
                elif [ -r /etc/rc.status ]; then
                source /etc/rc.status
                [ zz`type -t rc_reset 2>/dev/null` == "zzfunction" ] && dtype="suse"

                # Then test against Debian, Ubuntu and friends
                elif [ -r /lib/lsb/init-functions ]; then
                source /lib/lsb/init-functions
                [ zz`type -t log_begin_msg 2>/dev/null` == "zzfunction" ] && dtype="debian"

                # Then test against Gentoo
                elif [ -r /etc/init.d/functions.sh ]; then
                source /etc/init.d/functions.sh
                [ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && dtype="gentoo"

                # For Slackware we currently just test if /etc/slackware-version exists
                # and isn't empty (TODO: Find a better way :)
                elif [ -s /etc/slackware-version ]; then
                dtype="slackware"
                fi
                echo $dtype



                Note that this will probably only work correctly in Bash. You could rewrite it for other shells.



                That being said, you might want to test for features, not for distributions. I'm not using this anymore simply because it became a maintenance burden. It's easier to rely on cross-distribution tools and solutions.




                Conceptually, what it does is, in order:




                • Pull in a known, "common init script function" type of file. Those are distribution-specific. If it doesn't exist, skip to next distribution check.

                • Check the existence of a specific, known-to-exist, often-used and unlikely to be renamed function from that core script. We do that using the type Bash builtin. type -t returns function if that symbol is a function. We prepend zz to the output from type -t 2>/dev/null because if the name isn't defined the output string would be empty and we'd get a syntax error about a missing left hand to the == operator. If the name we just checked isn't a function, skip to next distribution check, otherwise we found the distribution type.

                • Finally, echo the distribution type so the function output can be easily used in a case .. esac block.




                Edit in case you're trying to run this as a straight script: This script is supposed to get sourced or included from other scripts. It does not output anything on its own if you run it as-is. To test it, source it and then invoke the function, e.g.:



                source /path/to/this/script.sh
                get_distribution_type


                at the bash prompt.




                Edit: Please note that this script does not require root privileges. I urge you not to run it as root. Shouldn't harm anything, but there's no need.




                Found a link to a relevant mailing list post in the CVS log. Should be useful in unwrapping init script spaghetti.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 7 at 17:08









                baddy

                52




                52










                answered May 2 '09 at 23:15









                Mihai LimbăşanMihai Limbăşan

                2,9511819




                2,9511819












                • I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

                  – Gareth
                  May 3 '09 at 0:39











                • gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

                  – Mihai Limbăşan
                  May 3 '09 at 0:51











                • @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

                  – Mihai Limbăşan
                  May 3 '09 at 1:20











                • @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

                  – Gareth
                  May 3 '09 at 6:33











                • @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

                  – Mihai Limbăşan
                  May 3 '09 at 7:24

















                • I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

                  – Gareth
                  May 3 '09 at 0:39











                • gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

                  – Mihai Limbăşan
                  May 3 '09 at 0:51











                • @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

                  – Mihai Limbăşan
                  May 3 '09 at 1:20











                • @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

                  – Gareth
                  May 3 '09 at 6:33











                • @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

                  – Mihai Limbăşan
                  May 3 '09 at 7:24
















                I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

                – Gareth
                May 3 '09 at 0:39





                I haven't looked at why but it returns to prompt on Debian Lenny (5.0).

                – Gareth
                May 3 '09 at 0:39













                gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

                – Mihai Limbăşan
                May 3 '09 at 0:51





                gyaresu, have you actually invoked the get_distribution_type function? I've edited the post to clarify (see at the bottom.)

                – Mihai Limbăşan
                May 3 '09 at 0:51













                @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

                – Mihai Limbăşan
                May 3 '09 at 1:20





                @gyaresu: If the above wasn't the problem, can you please try to replace log_begin_msg in the Debian section with log_warning_msg and retry? Might have gotten the function name wrong. In any case, it should have returned "unknown" if that function wasn't htere, but still.

                – Mihai Limbăşan
                May 3 '09 at 1:20













                @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

                – Gareth
                May 3 '09 at 6:33





                @Mihai Doh! Sorry. Didn't read the script properly. Was early, no coffee. My apologise. gyaresu@debian:~/bin$ source server_version.sh gyaresu@debian:~/bin$ get_distribution_type debian

                – Gareth
                May 3 '09 at 6:33













                @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

                – Mihai Limbăşan
                May 3 '09 at 7:24





                @gyaresu: Thanks! That's good, should help jldugger to know that it works on Debian as well :)

                – Mihai Limbăşan
                May 3 '09 at 7:24











                17














                You can find the kernel version by running uname -a, finding the distro version is dependant on the distro.



                On Ubuntu and some other OS' you can run lsb_release -a or read /etc/lsb_release



                Debian stores the version in /etc/debian_version






                share|improve this answer























                • +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

                  – Josh Kelley
                  Jun 10 '09 at 10:52











                • for just the description 'lsb_release -ds'.

                  – flickerfly
                  Sep 12 '14 at 16:12















                17














                You can find the kernel version by running uname -a, finding the distro version is dependant on the distro.



                On Ubuntu and some other OS' you can run lsb_release -a or read /etc/lsb_release



                Debian stores the version in /etc/debian_version






                share|improve this answer























                • +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

                  – Josh Kelley
                  Jun 10 '09 at 10:52











                • for just the description 'lsb_release -ds'.

                  – flickerfly
                  Sep 12 '14 at 16:12













                17












                17








                17







                You can find the kernel version by running uname -a, finding the distro version is dependant on the distro.



                On Ubuntu and some other OS' you can run lsb_release -a or read /etc/lsb_release



                Debian stores the version in /etc/debian_version






                share|improve this answer













                You can find the kernel version by running uname -a, finding the distro version is dependant on the distro.



                On Ubuntu and some other OS' you can run lsb_release -a or read /etc/lsb_release



                Debian stores the version in /etc/debian_version







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 2 '09 at 23:14









                Adam GibbinsAdam Gibbins

                6,14622442




                6,14622442












                • +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

                  – Josh Kelley
                  Jun 10 '09 at 10:52











                • for just the description 'lsb_release -ds'.

                  – flickerfly
                  Sep 12 '14 at 16:12

















                • +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

                  – Josh Kelley
                  Jun 10 '09 at 10:52











                • for just the description 'lsb_release -ds'.

                  – flickerfly
                  Sep 12 '14 at 16:12
















                +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

                – Josh Kelley
                Jun 10 '09 at 10:52





                +1 for lsb_release (also works on Red Hat derivatives if the right package is installed)

                – Josh Kelley
                Jun 10 '09 at 10:52













                for just the description 'lsb_release -ds'.

                – flickerfly
                Sep 12 '14 at 16:12





                for just the description 'lsb_release -ds'.

                – flickerfly
                Sep 12 '14 at 16:12











                6














                Most distro's have a unique method of determining the particular distribution.



                For example:



                Redhat (And derivatives): /etc/redhat-release

                SUSE: /etc/SUSE-release


                There is a standard out there known as the Linux Standard Base or LSB.
                It defines that there should be a file called /etc/lsb-release or a program called lsb_release that will echo back information about your linux distro.



                lsb_release -a





                share|improve this answer























                • And of course, lsb_release does not exist on CentOS 6.

                  – Justin
                  Sep 21 '12 at 2:45















                6














                Most distro's have a unique method of determining the particular distribution.



                For example:



                Redhat (And derivatives): /etc/redhat-release

                SUSE: /etc/SUSE-release


                There is a standard out there known as the Linux Standard Base or LSB.
                It defines that there should be a file called /etc/lsb-release or a program called lsb_release that will echo back information about your linux distro.



                lsb_release -a





                share|improve this answer























                • And of course, lsb_release does not exist on CentOS 6.

                  – Justin
                  Sep 21 '12 at 2:45













                6












                6








                6







                Most distro's have a unique method of determining the particular distribution.



                For example:



                Redhat (And derivatives): /etc/redhat-release

                SUSE: /etc/SUSE-release


                There is a standard out there known as the Linux Standard Base or LSB.
                It defines that there should be a file called /etc/lsb-release or a program called lsb_release that will echo back information about your linux distro.



                lsb_release -a





                share|improve this answer













                Most distro's have a unique method of determining the particular distribution.



                For example:



                Redhat (And derivatives): /etc/redhat-release

                SUSE: /etc/SUSE-release


                There is a standard out there known as the Linux Standard Base or LSB.
                It defines that there should be a file called /etc/lsb-release or a program called lsb_release that will echo back information about your linux distro.



                lsb_release -a






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 2 '09 at 23:24









                Mark TurnerMark Turner

                2,19411316




                2,19411316












                • And of course, lsb_release does not exist on CentOS 6.

                  – Justin
                  Sep 21 '12 at 2:45

















                • And of course, lsb_release does not exist on CentOS 6.

                  – Justin
                  Sep 21 '12 at 2:45
















                And of course, lsb_release does not exist on CentOS 6.

                – Justin
                Sep 21 '12 at 2:45





                And of course, lsb_release does not exist on CentOS 6.

                – Justin
                Sep 21 '12 at 2:45











                6














                python -c 'import platform ; print platform.dist()[0]'


                code:
                http://hg.python.org/cpython/file/2.7/Lib/platform.py






                share|improve this answer

























                • Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

                  – heinrich5991
                  Dec 9 '12 at 14:11















                6














                python -c 'import platform ; print platform.dist()[0]'


                code:
                http://hg.python.org/cpython/file/2.7/Lib/platform.py






                share|improve this answer

























                • Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

                  – heinrich5991
                  Dec 9 '12 at 14:11













                6












                6








                6







                python -c 'import platform ; print platform.dist()[0]'


                code:
                http://hg.python.org/cpython/file/2.7/Lib/platform.py






                share|improve this answer















                python -c 'import platform ; print platform.dist()[0]'


                code:
                http://hg.python.org/cpython/file/2.7/Lib/platform.py







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Sep 22 '12 at 15:54









                Scott Pack

                13.4k84482




                13.4k84482










                answered Sep 19 '12 at 2:14









                jkeoghjkeogh

                6111




                6111












                • Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

                  – heinrich5991
                  Dec 9 '12 at 14:11

















                • Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

                  – heinrich5991
                  Dec 9 '12 at 14:11
















                Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

                – heinrich5991
                Dec 9 '12 at 14:11





                Great idea. I would suggest using python -c 'import platform; print(platform.dist()[0])', because that way it also works if the normal python defaults to python3.

                – heinrich5991
                Dec 9 '12 at 14:11











                5














                In addition to the other answers: If you just want to parse one file, most distros personalize the tty login via /etc/issue e.g.:




                Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel r (l).




                And yes I know it's suboptimal. :)






                share|improve this answer























                • It may be sub-optimal, but it is in the same place.

                  – Brad Gilbert
                  May 3 '09 at 3:17















                5














                In addition to the other answers: If you just want to parse one file, most distros personalize the tty login via /etc/issue e.g.:




                Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel r (l).




                And yes I know it's suboptimal. :)






                share|improve this answer























                • It may be sub-optimal, but it is in the same place.

                  – Brad Gilbert
                  May 3 '09 at 3:17













                5












                5








                5







                In addition to the other answers: If you just want to parse one file, most distros personalize the tty login via /etc/issue e.g.:




                Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel r (l).




                And yes I know it's suboptimal. :)






                share|improve this answer













                In addition to the other answers: If you just want to parse one file, most distros personalize the tty login via /etc/issue e.g.:




                Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel r (l).




                And yes I know it's suboptimal. :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 2 '09 at 23:21









                NodeNode

                1,48911215




                1,48911215












                • It may be sub-optimal, but it is in the same place.

                  – Brad Gilbert
                  May 3 '09 at 3:17

















                • It may be sub-optimal, but it is in the same place.

                  – Brad Gilbert
                  May 3 '09 at 3:17
















                It may be sub-optimal, but it is in the same place.

                – Brad Gilbert
                May 3 '09 at 3:17





                It may be sub-optimal, but it is in the same place.

                – Brad Gilbert
                May 3 '09 at 3:17











                4














                facter is a handy tool for this sort of discovery, although it probably uses some of the methods detailed above, and requires Ruby.






                share|improve this answer



























                  4














                  facter is a handy tool for this sort of discovery, although it probably uses some of the methods detailed above, and requires Ruby.






                  share|improve this answer

























                    4












                    4








                    4







                    facter is a handy tool for this sort of discovery, although it probably uses some of the methods detailed above, and requires Ruby.






                    share|improve this answer













                    facter is a handy tool for this sort of discovery, although it probably uses some of the methods detailed above, and requires Ruby.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 5 '09 at 0:52









                    CawflandsCawflands

                    2,46322327




                    2,46322327





















                        2














                        All you need to do is type uname -a at your favorite shell. That will print out the kernel name and version.






                        share|improve this answer



























                          2














                          All you need to do is type uname -a at your favorite shell. That will print out the kernel name and version.






                          share|improve this answer

























                            2












                            2








                            2







                            All you need to do is type uname -a at your favorite shell. That will print out the kernel name and version.






                            share|improve this answer













                            All you need to do is type uname -a at your favorite shell. That will print out the kernel name and version.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 5 '09 at 1:41







                            user1797




























                                2














                                I've found that cat /etc/*release* almost always works.






                                share|improve this answer



























                                  2














                                  I've found that cat /etc/*release* almost always works.






                                  share|improve this answer

























                                    2












                                    2








                                    2







                                    I've found that cat /etc/*release* almost always works.






                                    share|improve this answer













                                    I've found that cat /etc/*release* almost always works.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Oct 25 '09 at 6:42









                                    ibuysibuys

                                    613




                                    613





















                                        2














                                        I concur with Mark, Adam and Mihai (can't vote up due to insufficient reputation). Solutions based on LSB and its relative FHS will work with most distributions and are likely to continue working in future. LSB and FHS are your friends.






                                        share|improve this answer



























                                          2














                                          I concur with Mark, Adam and Mihai (can't vote up due to insufficient reputation). Solutions based on LSB and its relative FHS will work with most distributions and are likely to continue working in future. LSB and FHS are your friends.






                                          share|improve this answer

























                                            2












                                            2








                                            2







                                            I concur with Mark, Adam and Mihai (can't vote up due to insufficient reputation). Solutions based on LSB and its relative FHS will work with most distributions and are likely to continue working in future. LSB and FHS are your friends.






                                            share|improve this answer













                                            I concur with Mark, Adam and Mihai (can't vote up due to insufficient reputation). Solutions based on LSB and its relative FHS will work with most distributions and are likely to continue working in future. LSB and FHS are your friends.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Nov 10 '09 at 3:11









                                            David J. LiszewskiDavid J. Liszewski

                                            218512




                                            218512





















                                                2














                                                You can also get the version by



                                                cat /proc/version


                                                o/p:




                                                Linux version 2.6.17-13mdv (rtp@octopus.mandriva.com) (gcc version
                                                4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)) #1 SMP Fri Mar 23 19:03:31 UTC 2007







                                                share|improve this answer





























                                                  2














                                                  You can also get the version by



                                                  cat /proc/version


                                                  o/p:




                                                  Linux version 2.6.17-13mdv (rtp@octopus.mandriva.com) (gcc version
                                                  4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)) #1 SMP Fri Mar 23 19:03:31 UTC 2007







                                                  share|improve this answer



























                                                    2












                                                    2








                                                    2







                                                    You can also get the version by



                                                    cat /proc/version


                                                    o/p:




                                                    Linux version 2.6.17-13mdv (rtp@octopus.mandriva.com) (gcc version
                                                    4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)) #1 SMP Fri Mar 23 19:03:31 UTC 2007







                                                    share|improve this answer















                                                    You can also get the version by



                                                    cat /proc/version


                                                    o/p:




                                                    Linux version 2.6.17-13mdv (rtp@octopus.mandriva.com) (gcc version
                                                    4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)) #1 SMP Fri Mar 23 19:03:31 UTC 2007








                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Oct 1 '15 at 18:04









                                                    Nixphoe

                                                    4,05872848




                                                    4,05872848










                                                    answered Jun 10 '09 at 9:12









                                                    prasannaprasanna

                                                    7615




                                                    7615





















                                                        1














                                                        The version of linux is a hard question. If we look at it narrowly we have the kernel version you can get with "uname -r". Distribution version is mostly irrellevant. Some distributions are better (enterprise distributions such as Redhat Enterprise Linux). Other distributions like Gentoo are basically moving targets that have no sensible version at all.
                                                        If you need to do things based on version, take a look at major components that are relevant to you:



                                                        Component Version command
                                                        glibc /lib/libc.so.6
                                                        gcc gcc --version
                                                        X xdpyinfo
                                                        libX11 pkg-config --modversion x11
                                                        gtk+ pkg-config --modversion gtk+-2.0
                                                        qt-4 pkg-config --modversion QtCore

                                                        etc...





                                                        share|improve this answer



























                                                          1














                                                          The version of linux is a hard question. If we look at it narrowly we have the kernel version you can get with "uname -r". Distribution version is mostly irrellevant. Some distributions are better (enterprise distributions such as Redhat Enterprise Linux). Other distributions like Gentoo are basically moving targets that have no sensible version at all.
                                                          If you need to do things based on version, take a look at major components that are relevant to you:



                                                          Component Version command
                                                          glibc /lib/libc.so.6
                                                          gcc gcc --version
                                                          X xdpyinfo
                                                          libX11 pkg-config --modversion x11
                                                          gtk+ pkg-config --modversion gtk+-2.0
                                                          qt-4 pkg-config --modversion QtCore

                                                          etc...





                                                          share|improve this answer

























                                                            1












                                                            1








                                                            1







                                                            The version of linux is a hard question. If we look at it narrowly we have the kernel version you can get with "uname -r". Distribution version is mostly irrellevant. Some distributions are better (enterprise distributions such as Redhat Enterprise Linux). Other distributions like Gentoo are basically moving targets that have no sensible version at all.
                                                            If you need to do things based on version, take a look at major components that are relevant to you:



                                                            Component Version command
                                                            glibc /lib/libc.so.6
                                                            gcc gcc --version
                                                            X xdpyinfo
                                                            libX11 pkg-config --modversion x11
                                                            gtk+ pkg-config --modversion gtk+-2.0
                                                            qt-4 pkg-config --modversion QtCore

                                                            etc...





                                                            share|improve this answer













                                                            The version of linux is a hard question. If we look at it narrowly we have the kernel version you can get with "uname -r". Distribution version is mostly irrellevant. Some distributions are better (enterprise distributions such as Redhat Enterprise Linux). Other distributions like Gentoo are basically moving targets that have no sensible version at all.
                                                            If you need to do things based on version, take a look at major components that are relevant to you:



                                                            Component Version command
                                                            glibc /lib/libc.so.6
                                                            gcc gcc --version
                                                            X xdpyinfo
                                                            libX11 pkg-config --modversion x11
                                                            gtk+ pkg-config --modversion gtk+-2.0
                                                            qt-4 pkg-config --modversion QtCore

                                                            etc...






                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered May 3 '09 at 17:46









                                                            Paul de VriezePaul de Vrieze

                                                            1313




                                                            1313





















                                                                1














                                                                You can also check the Grub menu, usually gives you a bunch of distro/version info :-)






                                                                share|improve this answer



























                                                                  1














                                                                  You can also check the Grub menu, usually gives you a bunch of distro/version info :-)






                                                                  share|improve this answer

























                                                                    1












                                                                    1








                                                                    1







                                                                    You can also check the Grub menu, usually gives you a bunch of distro/version info :-)






                                                                    share|improve this answer













                                                                    You can also check the Grub menu, usually gives you a bunch of distro/version info :-)







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Jun 10 '09 at 9:55









                                                                    Antoine BenkemounAntoine Benkemoun

                                                                    6,66433459




                                                                    6,66433459





















                                                                        -1














                                                                        FusionInventory is a cross-platform lightweight inventory tool that can get this information on many Linux distros but also on BSDs, Windows, MacOS X and other unices.



                                                                        If available, they use lsb_release (as mentioned a few times above), but if not they have a very useful list of files and regular expressions to check the distro name and version: https://github.com/fusinv/fusioninventory-agent/blob/2.2.x/lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Distro/NonLSB.pm#L16.



                                                                        I would recommend using FusionInventory itself to get this information, rather than reimplementing your own scripts with this logic, as their community will maintain this functionality up to date. You could either use the agent on it's own (it outputs a XML/JSON file which is easy to parse) or couple it with a wider solution to manage the machines in your network like GLPI or Rudder, depending on your needs.






                                                                        share|improve this answer























                                                                        • This would be a good solution if it didn't have external dependencies of Perl modules

                                                                          – Will Sheppard
                                                                          Jan 8 '16 at 13:53
















                                                                        -1














                                                                        FusionInventory is a cross-platform lightweight inventory tool that can get this information on many Linux distros but also on BSDs, Windows, MacOS X and other unices.



                                                                        If available, they use lsb_release (as mentioned a few times above), but if not they have a very useful list of files and regular expressions to check the distro name and version: https://github.com/fusinv/fusioninventory-agent/blob/2.2.x/lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Distro/NonLSB.pm#L16.



                                                                        I would recommend using FusionInventory itself to get this information, rather than reimplementing your own scripts with this logic, as their community will maintain this functionality up to date. You could either use the agent on it's own (it outputs a XML/JSON file which is easy to parse) or couple it with a wider solution to manage the machines in your network like GLPI or Rudder, depending on your needs.






                                                                        share|improve this answer























                                                                        • This would be a good solution if it didn't have external dependencies of Perl modules

                                                                          – Will Sheppard
                                                                          Jan 8 '16 at 13:53














                                                                        -1












                                                                        -1








                                                                        -1







                                                                        FusionInventory is a cross-platform lightweight inventory tool that can get this information on many Linux distros but also on BSDs, Windows, MacOS X and other unices.



                                                                        If available, they use lsb_release (as mentioned a few times above), but if not they have a very useful list of files and regular expressions to check the distro name and version: https://github.com/fusinv/fusioninventory-agent/blob/2.2.x/lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Distro/NonLSB.pm#L16.



                                                                        I would recommend using FusionInventory itself to get this information, rather than reimplementing your own scripts with this logic, as their community will maintain this functionality up to date. You could either use the agent on it's own (it outputs a XML/JSON file which is easy to parse) or couple it with a wider solution to manage the machines in your network like GLPI or Rudder, depending on your needs.






                                                                        share|improve this answer













                                                                        FusionInventory is a cross-platform lightweight inventory tool that can get this information on many Linux distros but also on BSDs, Windows, MacOS X and other unices.



                                                                        If available, they use lsb_release (as mentioned a few times above), but if not they have a very useful list of files and regular expressions to check the distro name and version: https://github.com/fusinv/fusioninventory-agent/blob/2.2.x/lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Distro/NonLSB.pm#L16.



                                                                        I would recommend using FusionInventory itself to get this information, rather than reimplementing your own scripts with this logic, as their community will maintain this functionality up to date. You could either use the agent on it's own (it outputs a XML/JSON file which is easy to parse) or couple it with a wider solution to manage the machines in your network like GLPI or Rudder, depending on your needs.







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Sep 21 '12 at 7:04









                                                                        Jonathan ClarkeJonathan Clarke

                                                                        1,3671923




                                                                        1,3671923












                                                                        • This would be a good solution if it didn't have external dependencies of Perl modules

                                                                          – Will Sheppard
                                                                          Jan 8 '16 at 13:53


















                                                                        • This would be a good solution if it didn't have external dependencies of Perl modules

                                                                          – Will Sheppard
                                                                          Jan 8 '16 at 13:53

















                                                                        This would be a good solution if it didn't have external dependencies of Perl modules

                                                                        – Will Sheppard
                                                                        Jan 8 '16 at 13:53






                                                                        This would be a good solution if it didn't have external dependencies of Perl modules

                                                                        – Will Sheppard
                                                                        Jan 8 '16 at 13:53


















                                                                        draft saved

                                                                        draft discarded
















































                                                                        Thanks for contributing an answer to Server Fault!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid


                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.

                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function ()
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f3331%2fhow-do-i-find-out-what-version-of-linux-is-running%23new-answer', 'question_page');

                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        Popular posts from this blog

                                                                        Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                                                                        Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                                                                        Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020