Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

What is the best way to get the flavor of linux installed on any server? For example if the server is RedHat or CentOS, I can simply do:

cat /etc/redhat-release
CentOS release 6.3 (Final)

Where do all the other major distributions store their details file? Thanks.

share|improve this question

marked as duplicate by Michael Hampton, Ward, Scott Pack, mulaz, MDMarra Sep 26 '12 at 18:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers 4

up vote 3 down vote accepted

Well, how many variants are you looking at? RHEL (and clones) and Debian and Ubuntu.

Ideally, lsb_release -i -s output would work... But there may be cases where that command is not available.

A more comprehensive example is available at: How do I find out what version of Linux is running?

share|improve this answer
    
python -c 'import platform ; print platform.dist()[0]' seems to work on CentOS, do you have access to a Debian based distro to try it? –  Justin Sep 21 '12 at 2:48
    
Yes. I got: root@deore:/volumes# python -c 'import platform ; print platform.dist()[0]' Ubuntu –  ewwhite Sep 21 '12 at 2:58
    
Also lsb_release is not available on CentOS. :( –  Justin Sep 21 '12 at 3:06
    
@Justin [root@xt ~]# lsb_release -i Distributor ID: CentOS The name of the package is redhat-lsb. –  ewwhite Sep 21 '12 at 8:58

Odd that no one mentioned /etc/issue in the previously linked example. I've used that file for years.

Nowadays I just use 'facter' with Puppet to get that information, grep & awk the output.

share|improve this answer

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

If available, they use lsb_release as described by @ewwhite 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 FusionInventoy 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

You can use facter to find out a lot of details in a nicely normalized way. It's part of puppet.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.