How does one identify the linux distro in use?

3

What I normally do to at least get some idea of what branch we're talking about, I try to run apt-get, pacman, yum and all other common package managers that I can remember off the top of my head, but I'm sure there's a better way, so: Is there a simple way of, by using shell only, identifying which linux distribution you just logged in to?

Jarmund

Posted 2015-06-18T23:27:15.043

Reputation: 5 155

Answers involving the kernel version (e.g. uname -a and cat /proc/version aren't correct, since the concept of a "distribution" is foreign to the Linux kernel. Note that the Linux system may not be from any distro at all, that is, it could be a custom-built kernel and rootfs. – sawdust – 2015-06-18T23:50:40.060

@DavidPostill It would be great if /etc/lsb-release was more de facto - it was only present on 1 of the 4 I tried below. – Paul – 2015-06-18T23:58:03.120

lsb-release is usually optional – Thomas Dickey – 2015-06-19T00:10:12.420

Cat /etc/release – Alec Istomin – 2015-06-19T04:03:39.137

Answers

3

It depends on the distro.

Debian and relatives use

     lsb_release -a
     cat /etc/lsb-release

either one should be fine. But, despite this being related to LSB (Linux Standard Base), not all distros have it. If you get no reply from the above commands, you should try

      ls /etc/*release

and then look inside whichever file you found. You must be careful to this: while RedHat does have /etc/redhat-release, others, like Arch Linux, have an empty /etc/arch-release file, and the one that does contain the info you are looking for is /etc/os-release.

So, YMMV.

MariusMatutiae

Posted 2015-06-18T23:27:15.043

Reputation: 41 321

2

It may not be foolproof, but /proc/version should at least give you a ballpark:

Redhat derivative:

# cat /proc/version 
Linux version 2.6.18-92cp (builder@Lnx30BccCmp5) (gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)) #1 SMP Wed Apr 8 17:12:19 IDT 2015

Ubuntu:

$ cat /proc/version
Linux version 3.13.0-24-generic (buildd@panlong) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014

Debian:

$ cat /proc/version 
Linux version 3.2.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.2.65-1+deb7u1      

Centos:

# cat /proc/version 
Linux version 2.6.18-400.el5xen (mockbuild@builder17.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-55)) #1 SMP Thu Dec 4 13:29:23 EST 2014

Paul

Posted 2015-06-18T23:27:15.043

Reputation: 52 173

As advertised, not foolproof, but a lot easier than my method of checking the package manager. /proc/version on Mint Ubuntu, but it's close enough. – Jarmund – 2015-06-18T23:38:22.417

1

I use screenfetch multi-linux-platform script utility:

enter image description here

Drakonoved

Posted 2015-06-18T23:27:15.043

Reputation: 314

0

On modern Fedora and Debian (and Arch, CentOS, CoreOS, Mageia, openSUSE, Red Hat Enterprise Linux, SUSE Linux Enterprise Server, Ubuntu, and others) the easiest way is to look at /etc/os-release or run hostnamectl status.

In a script, you could simply do

#!/bin/sh
source /etc/os-release
echo $PRETTY_NAME

For example:

$ source /etc/os-release
$ echo $PRETTY_NAME
Fedora 25 (Workstation Edition)

...

$ source /etc/os-release 
$ echo $PRETTY_NAME
Debian GNU/Linux 8 (jessie)

Of course, if you need to identify old versions or non-systemd distros as well, you could simply start with this approach if /etc/os-release exists, and if it doesn't, fall back to looking for lsb_release, /etc/redhat-release, trying to figure it out from /proc/version, or some other heuristic.

See Detecting Linux distribution name and version on Stack Overflow Documentation for more.

mattdm

Posted 2015-06-18T23:27:15.043

Reputation: 2 324

0

uname -a

Should do the trick. It will display system information on the distro you're logged in.

cat /etc/lsb-release 

Should also display the distro name and version.

KenWeiLL

Posted 2015-06-18T23:27:15.043

Reputation: 1

Nope, it only shows hostname, kernel and platform, not distro. – Jarmund – 2015-06-18T23:39:31.137

Okay. I updated my answer. That should display the distro name and version. Or at least it did on mine on Linux Mint. – KenWeiLL – 2015-06-19T00:12:19.337