Answers to: How can I programatically determine the Linux distribution?http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution<p>There are various ways of finding out what Linux distribution is currently running, using commands such as:</p> <pre><code>uname -a cat /etc/*-release cat /etc/*-version lsb_release -ri </code></pre> <p>Each of them provides me with <em>human-readable</em> information about my system, but they don't seem reliable nor can be easily parsed. Is there some script that can determine popular Linux distributions with accuracy and output something simple like <code>Ubuntu</code> / <code>Slackware</code> / <code>CentOS</code> / <code>Mandriva</code> / etc?</p>enTue, 16 Jul 2013 04:03:34 -0400Answer by amcohenhttp://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution/3133<p>Here's a skeletan of a Korn/Bash function to do it:</p> <p>function get_distro { if [[ -r /etc/redhat-relase ]]; then set -- $(cat /etc/redhat-relase) case $1 in Red) echo Redhat;; Fedora) echo Fedora;; CentOS) echo CentOS;; *) echo ??? esac elif [[ -r /etc/debian_version ]]; then echo Debian else echo UNKNOWN fi }</p>amcohenTue, 16 Jul 2013 04:03:34 -0400http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution/3133Answer by Jazzhttp://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution/2639<p><a href="http://www.novell.com/coolsolutions/feature/11251.html">Here's</a> one. You could enhance this script by first using the other ways of finding out which distribution is running before using uname. A combination of those commands should do the trick for any distribution.</p>JazzWed, 13 Jul 2011 16:04:20 -0400http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution/2639Comment by Jazz on DMon's answerhttp://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution#2638<p>Furthermore not all distributions report something useful using lsb_release. My ArchLinux configuration prints "n/a" for example.</p>JazzWed, 13 Jul 2011 15:58:12 -0400http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution#2638Comment by DMon on DMon's answerhttp://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution#2636<p>CentOS 6 does. Just tried it on there. But you are correct not every Distro does it the same however lsb seems to be more common in the newest batch of updates.</p>DMonWed, 13 Jul 2011 15:20:02 -0400http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution#2636Comment by fardelian on DMon's answerhttp://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution#2634<p>That only works on some distributions. For example, <em>CentOS</em> doesn't have the <code>lsb_release</code> executable.</p>fardelianWed, 13 Jul 2011 14:58:53 -0400http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution#2634Answer by DMonhttp://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution/2633<p>Not sure what all you want it to show. </p> <p><code>$ lsb_release -is</code> </p> <p>will give you just the Distribution</p>DMonWed, 13 Jul 2011 14:05:34 -0400http://linuxexchange.org/questions/2632/how-can-i-programatically-determine-the-linux-distribution/2633