27

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

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Seiti
  • 2,138
  • 2
  • 21
  • 33

12 Answers12

29

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
  • 47,594
  • 12
  • 108
  • 150
  • 2
    lsb_release -d gave a much better result for me. -i gave "Distributor ID: CentOS". -d gave "Description: CentOS release 5.2 (Final)". – nickf Mar 04 '09 at 14:21
29
cat /etc/*release

Most distributions put a release file in /etc/ (like /etc/redhat-release, /etc/gentoo-release, etc.) which usually has the version number of your distribution in it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
8

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
  • 19,908
  • 6
  • 73
  • 83
  • 1
    More narrowly, `lsb_release` only works on Linux systems which attempt to adhere to the [Linux Standard Base](https://en.wikipedia.org/wiki/Linux_Standard_Base) specifications. – tripleee Jul 28 '16 at 06:39
3

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
  • 12,661
  • 5
  • 35
  • 30
2

There are different commands you can use to check which distribution is in use. Here I am mentioning only 5 of them.

  1. lsb_relase -a

lsb_release provides distribution-specific information. Whereas -a display all information about the distribution. You can also use -d which only shows the description.

  1. uname -a

uname also provides system information. Whereas -a display all information. You can use man uname for other options.

  1. cat /etc/*release

You can also use cat command to print out all specific release information from etc folder. This command actually reads the lsb-release and os-release files from the /etc folder.

  1. cat /etc/issue

This command reads the issue file from the /etc folder.

  1. cat /proc/version

This command reads the version file from the /proc folder. /proc folder contains information about system process.

N Randhawa
  • 8,773
  • 3
  • 43
  • 47
1

In my .cshrc I have

setenv DISTRO `sed -e 's/.*(//' -e 's/)).*//' /proc/version`

For ksh / Bash users, I presume it translates to

export DISTRO=`sed -e 's/.*(//' -e 's/)).*//' /proc/version`

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

Update August 2016 I have not used Linux in this way for a while (2008 is a long time ago). It seems that this does not work anymore for the systems I now have.

hoijui
  • 3,615
  • 2
  • 33
  • 41
Andrew Stein
  • 12,880
  • 5
  • 35
  • 43
1

I found that the /etc/issue usually has something about the distribution in use.

But I don't know about its availability on all distributions.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Seiti
  • 2,138
  • 2
  • 21
  • 33
  • 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 Nov 05 '08 at 05:15
  • Yep, it works on Ubuntu. I got "`Ubuntu 16.04.1 LTS \n \l`". Yes, \n and \l are literal (not ASCII 13 and 10). – Peter Mortensen Jul 19 '17 at 17:25
1

The proc file system: A directory in Linux with all the hardware level information. So just type

cd /proc/

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rahijain
  • 885
  • 1
  • 8
  • 10
  • 2
    So `cat /proc/version` will return information about the version. – Henrik May 18 '16 at 09:19
  • `cd /proc` by itself does nothing useful. You don't have to `cd` to a directory to read the files there, and normally should not need to (though in an interactive shell, it saves you from typing long paths; but scripts generally rarely need `cd`). – tripleee Jul 28 '16 at 06:50
  • Many files in `proc` use C strings, so they are not technically pure text. Try `tr '\000' '\012' – tripleee Jul 28 '16 at 06:51
0

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
  • 176
  • 6
  • 1
    uname shows the version and architecture, but not the distribution (Red Hat, SuSE, Ubuntu, ....) – Adam Liss Nov 05 '08 at 03:46
  • 1
    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 Nov 06 '08 at 07:50
0
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
  • 7,216
  • 2
  • 34
  • 46
0

NeoFetch

... is a quite professional BASH script that should have all the info you might desire.

(Disclaimer: I am not affiliated with it)

Usage

neofetch --stdout | grep '^OS: ' | sed -e 's/OS:[[:space:]]\+//'

might give:

Debian GNU/Linux 11 (bullseye) x86_64

but there is much more info.

Installation

Options:

  1. system packaage neofetch

  2. If that is not available, either see the official installation instructions

  3. or for a hacky one-time use - if you have faith and an internet connection - you could use:

    wget 'https://raw.githubusercontent.com/dylanaraps/neofetch/master/neofetch' \
        && bash neofetch --stdout \
        && rm neofetch
    
hoijui
  • 3,615
  • 2
  • 33
  • 41
-1

Try uname -a

matt b
  • 138,234
  • 66
  • 282
  • 345