There are various ways of finding out what Linux distribution is currently running, using commands such as:

uname -a
cat /etc/*-release
cat /etc/*-version
lsb_release -ri

Each of them provides me with human-readable 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 Ubuntu / Slackware / CentOS / Mandriva / etc?

asked 13 Jul '11, 05:42

fardelian's gravatar image

accept rate: 0%

Not sure what all you want it to show.

$ lsb_release -is

will give you just the Distribution


answered 13 Jul '11, 14:05

DMon's gravatar image

accept rate: 0%

That only works on some distributions. For example, CentOS doesn't have the lsb_release executable.

(13 Jul '11, 14:58) fardelian

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.

(13 Jul '11, 15:20) DMon

Furthermore not all distributions report something useful using lsb_release. My ArchLinux configuration prints "n/a" for example.

(13 Jul '11, 15:58) Jazz ♦

Here's 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.


answered 13 Jul '11, 16:04

Jazz's gravatar image

Jazz ♦
accept rate: 33%

Here's a skeletan of a Korn/Bash function to do it:

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 }


answered 16 Jul '13, 04:03

amcohen's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 13 Jul '11, 05:42

Seen: 3,948 times

Last updated: 16 Jul '13, 04:03

powered by OSQA