views:

958

answers:

10

Sometimes I need to access some servers running Linux (or maybe another Unix-like SO), but I don't know how to verify which distro is in use on the server (there are times that even the "responsible" for the server doesn't know).

Is there a easy and reliable way to discover that, one that is uniform and consistent across all of them?

A: 

Try uname -a

matt b
A: 

You can use 'uname':

[anton@localhost ~]$ uname -a
Linux localhost 2.6.26-ARCH #1 SMP PREEMPT Tue Aug 26 21:15:43 UTC 2008 i686 AMD Athlon(tm) 64 Processor 3000+ AuthenticAMD GNU/Linux
Yojik
uname shows the version and architecture, but not the distribution (Red Hat, SuSE, Ubuntu, ....)
Adam Liss
normally the distribution adds to the version, like in the example the distribution is Arch Linux. And for Arch, all the other mentioned ideas except /etc/issue don't work as well. So why the downvote?
ypnos
A: 
uname -r

should print the kernel version currently running (at least, it does for Linux, don't know if it's the same for *BSD or others). That's not the same as the distro but the kernel version often includes the distro name if it's customised, like "2.6.27-gentoo-r1" or something.

Init often prints something at boot, but that's not much good when it's running.

Otherwise as far as I know there isn't anything universal.

Peter
+15  A: 

lsb_release -i may work for you.

More detail is available with lsb_release -a

Some discussion at http://etbe.coker.com.au/2007/08/30/identifying-the-distribution-of-a-linux-system/

Adam Liss
lsb_release -d gave a much better result for me. -i gave "Distributor ID: CentOS". -d gave "Description: CentOS release 5.2 (Final)".
nickf
Very usefull to me thanks!
ojblass
+10  A: 
cat /etc/*release

I'm surprised that noone has mentioned that most distributions put a release file in /etc/ (like /etc/redhat-release, /etc/gentoo-release, etc) which usually has the version number of your distro in it.

Evan Teran
A: 

In my .cshrc I have

setenv DISTRO ` cat /proc/version | sed 's/.*(//' | sed 's/)).*//' `

For ksh / bash users, I presume it translates to

export DISTRO=` cat /proc/version | sed 's/.*(//' | sed 's/)).*//' `

and of course this may not work for your favorite distro. (I have has issues with Oracle's Unbreakable Linux giving something similar to Redhat, but it was good enough for my purposes.)

Andrew Stein
+4  A: 

This is, annoyingly, a harder problem than it appears.

For Linux systems, use lsb_release.

$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 8.04.1
Release:        8.04
Codename:       hardy
$ lsb_release -i
Distributor ID: Ubuntu

This has the limitation that lsb_release works only for Linux releases.

For all Unix systems, you can also parse up uname.

$ uname -a
Linux blue-laptop 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux

You can find some information about the systems and distributions at the uname Wikipedia page.

Charles Merriam
A: 

I found that the /etc/issue usually have something about the distro in use. But I don't know about it's availability on all distros.

Seiti
Unfortunately, many distros have a very minimal /etc/issue which just has something like "This is \n.\O (\s \m \r) \t" in it, which gives no real information about the distro.
Evan Teran
+2  A: 

You should ask yourself if you really need to know which distro is in use (perhaps because you want to build a package specific for this distribution). In many other cases it is a far better idea, to just test and see if the features you need are there or not. This might look like a lot more work because you have to test every feature one by one but this way, your software becomes far more flexible.

WMR
something like what 'configure' do, huh? good point
Seiti
Yupp, something like `configure` or CMake: http://www.cmake.org/
WMR
A: 

Proc : A directory in linux which all the hardware level information. So just type

cd /proc/

There you will find gold mine of information stored in text file for all arbitary information about system.

rahijain