How to know linux distro version

How to know which Linux Distribution I’m using? [closed]

Moved to https://superuser.com/questions/80251/how-to-know-which-linux-distribution-im-using How to know which Linux Distribution I’m using? uname -a gives Linux xxxxxx.net 2.6.9-42.0.3.EL.wh1smp #1 SMP Fri Aug 14 15:48:17 MDT 2009 i686 i686 i386 GNU/Linux How can I know this is Ubuntu/Debian/Fedora or Redhat? I uses /etc/init.d/serviced restart for restarting serevices, seems it is not Redhat family Update:

[~]$ cat /etc/issue cat: /etc/issue: No such file or directory [~]$ cat /etc/issue.net cat: /etc/issue.net: No such file or directory [~]$ lsb_release -a -sh: lsb_release: command not found [~]$ cat /etc/*-release cat: /etc/*-release: No such file or directory [~]$ cat /etc/*-version cat: /etc/*-version: No such file or directory [~]$ cat /etc/*release cat: /etc/*release: No such file or directory [~]$ cat /etc/*_release cat: /etc/*_release: No such file or directory [~]$ cat /etc/*version cat: /etc/*version: No such file or directory [~]$ 

If you are looking for a reliable way to make your program behave accordingly on any given distribution, I’d suggest updating your question before its migrated.

6 Answers 6

You could also try /etc/*-version

[itflux][~]$ cat /etc/*-release cat: /etc/*-release: No such file or directory [itflux][~]$ cat /etc/*-version cat: /etc/*-version: No such file or directory

If you have lsb_release command,

will tell you (or just use lsb_release -i ).

Edit: Looks like you’re on a Red Hat system. A google search on your uname output suggests so. This is not programmatic, of course!

lsb_relase was created to ease the pain of determining the distro easily from within a program. A lot of systems out in the wild and still in use lack this altogether.

You’re right. If someone is using that old a distribution, the first step should probably be to upgrade to a more recent version! 🙂

/etc/issue or /etc/issue.net give a good clue. Newer distros provide /etc/lsb-release which make it easier to determine exact strings progmatically, i.e. distro name / major & minor release / web site, etc.

In the absence of /etc/lsb-release, its much more difficult, hence the creation of lsb-release.

Читайте также:  Astra linux network config

As Alok said, it looks like you are on a rather ancient (or extremely sparse) system. I don’t think this is a case that you can (reliably) progmatically determine with a few lines of code.

If all else fails, check to see what kind of package manager is in use (apt / rpm / others), check to see if /etc/init.d is a symlink (rpm / RH distros) or a directory (debian based distros) .. and you have a pretty good clue as to what you can expect to be present in the root file system as far as structure.

Источник

5 Linux Commands to Check Distro Name and Version

When working with an unknown server, the first task of a sys admin is to gather some information about the system, like what OS is it running, what version, what services are running and so on.

And there is no single command that can detect distribution specific information consistently across all linux distributions.

The command is different across Debian, CentOS and ArchLinux.

So in this post we are listing out some common commands that are used to detect distro specific information on linux. This includes the distro name and version.

1. lsb_release

The lsb_release command prints out distribution specific information about a linux distro.

On Ubuntu/debian based systems the command is available by default.

$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 11.04 Release: 11.04 Codename: natty

The lsb_release command is also available on CentOS/Fedora based systems, if the lsb core packages are installed.

# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.4 (Final) Release: 6.4 Codename: Final

2. /etc/*-release files

The /etc directory contains a couple of files that contains information about the distribution. The following files are present on Ubuntu/Debian based systems.

/etc/issue /etc/issue.net /etc/lsb-release /etc/os-release
$ cat /etc/issue Ubuntu 13.10 \n \l
$ cat /etc/issue.net Ubuntu 13.10
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=13.10 DISTRIB_CODENAME=saucy DISTRIB_DESCRIPTION="Ubuntu 13.10"
$ cat /etc/os-release NAME="Ubuntu" VERSION="13.10, Saucy Salamander" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 13.10" VERSION_ID="13.10" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

The file os-release contains a whole lot of information about the system.

CentOS/Fedora based systems contain similar files but with different names.

/etc/centos-release /etc/lsb-release /etc/redhat-release /etc/system-release
# cat /etc/centos-release CentOS release 6.4 (Final)
# cat /etc/lsb-release LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
# cat /etc/redhat-release CentOS release 6.4 (Final)
# cat /etc/system-release CentOS release 6.4 (Final)

Note that the lsb specific command and files are not present on CentOS by default. The redhat-lsb-core packages have to be installed to make lsb available. The /etc/lsb-release file does not print the distro information in a simple format.

Читайте также:  Find file with string linux

Fedora contains the /etc/os-release file, similar to ubuntu

$ cat /etc/os-release NAME=Fedora VERSION="18 (Spherical Cow)" ID=fedora VERSION_ID=18 PRETTY_NAME="Fedora 18 (Spherical Cow)" ANSI_COLOR="0;34" CPE_NAME="cpe:/o:fedoraproject:fedora:18"

3. cat /proc/version

The /proc/version file contains information about the kernel and some indication about the distro.

On a typical Ubuntu system the contents look like this

$ cat /proc/version Linux version 2.6.38-13-generic ([email protected]) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) ) #52-Ubuntu SMP Tue Nov 8 16:53:51 UTC 2011

On a typical CentOS system the output looks as follows

# cat /proc/version Linux version 2.6.32-358.11.1.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Wed Jun 12 03:34:52 UTC 2013

As can be seen above, the version information about the distro is not very clear, although it might be possible to deduce the distro in use.

Output on a RHEL 5 system

# cat /proc/version Linux version 2.6.18-028stab070.14 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Thu Nov 18 16:04:02 MSK 2010

4. uname -a

The uname command can also indicate which linux distro is in use, but gives very little information about it.

On Ubuntu, uname can clearly indicate the distribution name.

$ uname -a Linux enlightened-desktop 2.6.38-13-generic #52-Ubuntu SMP Tue Nov 8 16:53:51 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

However on CentOS, the exact distro name is not revealed.

# uname -a Linux dhcppc3 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Instead it reports the base distro name EL (Redhat).

Portable command

The following is an attempt to get a portable command for checking distro info across different linux systems.

$ cat /etc/[A-Za-z]*[_-][rv]e[lr]* squeeze/sid DISTRIB_ID=Ubuntu DISTRIB_RELEASE=11.04 DISTRIB_CODENAME=natty DISTRIB_DESCRIPTION="Ubuntu 11.04"

A simpler approach to make a portable command would be like this

$ lsb_release -a || cat /etc/redhat-release || cat /etc/*-release || cat /etc/issue

If one option fails, the command moves to the next one, until one of them works. The above command is not a well tested one and is expected to work fine only on ubuntu/debian and centos/fedora based systems.

That would print all unique lines from all /etc/*-release files. Works well on most distros.

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

Читайте также:  Linux reload usb rules

One Comment

  1. Tony August 10, 2021 at 10:10 pm Hi, Nice article.
    I personaly use this command in one of my scripts: (lsb_release -a 2>/dev/null || cat /etc/redhat-release || cat /etc/*-release || cat /etc/issue) | grep -i “centos\|ubuntu\|red *hat\|fedora\|debian\|slackware\|suse\|arch\|deepin\|kubuntu\|alpine” -o | sort -f | uniq -i -u It’s not getting all the Distributions out there, but enough for my use. Cheers,
    Tony

Источник

How to know linux distro version

How to check Debian version: the quick and easy way

How to check Debian version: the quick and easy way

Knowing which Debian version you have not only helps you to choose the right install package for a program – you also need it to get appropriate support in forums. There are several different methods to check your Debian version. In this step-by-step guide, we’ll explain how to check your version using Terminal and Hardinfo.

How to check your Ubuntu version: a guide

How to check your Ubuntu version: a guide

Knowing which Ubuntu version you’re running is helpful for different things. You can use this information to check whether programs are compatible with your system. Or you can include the version number in troubleshooting searches. It’s thus of crucial importance to know how to check your Ubuntu version. Keep reading to find out how to do so in a few simple clicks.

How to delete a Linux directory

How to delete a Linux directory

Sometimes you may need to delete an entire folder rather than just individual files. If you want to remove a Linux directory, there are several ways to do it. Here are a few basic solutions that use either File Manager or Terminal. We also explain what you can do if you don’t have the necessary rights.

How to delete files in Linux

How to delete files in Linux

Deleting files in Linux couldn’t be easier. Whether you use the file manager or work directly in the terminal with the command “rm”, you can remove Linux files in just a few clicks. Keep reading to find out how to remove single files, multiple files, files of a certain type, or entire folders.

How to use the Linux find command

How to use the Linux find command

While working on a Linux system the command line is frequently used. Many administrative tasks require you to find files and directories based on specific criteria. In doing so, Linux admins are accustomed to using the find command. Here, we’ll show you how the command works and how to use it as a handy tool.

Источник

Оцените статью
Adblock
detector