How to Discover What Linux Distribution Is in Use

How to discover what Linux distribution is in use

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/

Determine Linux distribution


cat /proc/version

Examples:

  1. Ubuntu:

    $ cat /proc/version
    Linux version 3.11.0-13-generic (buildd@roseapple) (gcc version 4.8.1 \
    (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013
  2. Red Hat / CentOS:

    $ cat /proc/version
    Linux version 2.6.32-220.13.1.el6.x86_64 (mockbuild@c6b6.bsys.dev.centos.org) \
    (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Apr 17 23:56:34 BST 2012

See also How To Know Which Linux Distribution You Are Using?

How to get Linux distribution name and version?

Try:

cat /etc/lsb-release

You can also try

lsb_release -a

Or:

cat /proc/version

Is there a way to find the linux os name and use it as an argument in an if statement?


source /etc/os-release
echo "$NAME"

Output:


Ubuntu

or


Red Hat Enterprise Linux Server

How do I identify the particular Linux flavor via command line?

Try the below command....
It worked for me...

cat /proc/version

Once you know that you are running Red Hat for example, you can get to the point with:

cat /etc/redhat-release

Or on Debian:

cat /etc/debian_version

or in general :

cat /etc/*-release

Also you could use the following command

cat /etc/issue

How to determine present operating system (including specific distribution in the case of Linux) in a Vala program?

Unless you are writing system level code (like package manager or OS configuration code), you shouldn't. A much better alternative is to use a library that already abstracts the distribution specifics for you.

If you absolutely have to there are two main ways to do it:

  1. At build time

    Here your build system should be responsible to detect the OS / distribution and either pass a define to the compiler (like -DDISTRO_UBUNTU) or write a config.vala file (possibly from a template config.vala.in with replacements, e.g. autotools has the AC_CONFIG_FILES facility to do this).

  2. At runtime

    Here your tool does the detection itself when it's running.

Which fits your application better is a design choice.

As to how to do it there are several things you can check:

  • uname -a (or other parameters, see man uname) will give you the kernel that is currently running.

  • lsb_release -a (not available on every distro, sometimes an optional package which you might have a package dependency to) will give you information on what distro and what distro version you are running on.

  • On Debian/Ubuntu derivates there is a file called /etc/debian_version which gives an indication of what release is currently installed. That information is not totally accurate though.

  • Some people are trying to read /etc/issue, but that is dangerous, since that file could be modified by the admin / the user.

  • You could ask the user which OS she is running.

There are also some os info libraries that you could use.

How to find Linux Distribution name using shell script?


$ lsb_release -i
Distributor ID: Fedora
$ lsb_release -i | cut -f 2-
Fedora

Check Linux distribution name

This works for me on Ubuntu:

('Ubuntu', '10.04', 'lucid')

I then used strace to find out what exactly the platform module is doing to find the distribution, and it is this part:

open("/etc/lsb-release", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=102, ...}) = 0
fstat64(3, {st_mode=S_IFREG|0644, st_size=102, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76b1000
read(3, "DISTRIB_ID=Ubuntu\nDISTRIB_RELEAS"..., 8192) = 102
read(3, "", 4096) = 0
read(3, "", 8192) = 0
close(3) = 0

So, there is /etc/lsb-release containing this information, which comes from Ubuntu's Debian base-files package.



Related Topics



Leave a reply



Submit