Which linux distro is running

Is there any way to find out which Linux Distribution is used?

I would like to show the user some help on specific operations in my program of the form: Please type «apt-get install foobar» to install the foobar feature. Is there anything to do this or do i have to leave it to the user and offer a dozend choices from Red Hat, Suse, Debian/Ubuntu, Mandriva, Slackware, Gentoo .

7 Answers 7

cat /etc/lsb-release

root@pierr-desktop:~# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=8.10 DISTRIB_CODENAME=intrepid DISTRIB_DESCRIPTION="Ubuntu 8.10" 

No it isn’t. Suse gives me: «Linux linux-kiste 2.6.27.7-9-default #1 SMP 2008-12-04 18:10:04 +0100 x86_64 x86_64 x86_64 GNU/Linux» Again no indication here about the Distribution and i don’t think that the /etc/lsb-release is even in the LSB spec. At least i haven’t seen it in 3.2

Instead of reading that file directly, use lsb_release -a (or specifically request the attributes you want, e.g. lsb_release -i -r -c -d ).

lsb_release -a might help on debian and apparented.

On Debian, it does not exist unless the lsb-release package is installed. That package is not marked essential and is not guaranteed to be present.

No, there is no generic way to find out which Linux distribution you are running on.

There is the lsb_release command, which is specified in the Linux Standard Base specification. But obviously this command is only present on LSB-compliant distributions, and many smaller or specialized distributions are not LSB-compliant. (For example, the distribution I am running on my FritzBox router is not.)

And if you are assuming an LSB-compliant distribution anyway, then why not simply package your application as an LSB package? That way it works the same on all LSB-compliant distributions.

Given that Linux can be built starting with one system and morphed into another, you may not be able to tell precisely which it currently is. Some distribution provide the lsb tools if they are LSB compliant, so that might help.

Some distributions provide a file /etc/dist-release. For example, I have a file /etc/arch-release that is empty.

That might indicate the distribution the kernel was built for, but that might be a long shot. My Arch linux kernel has no mention of Arch, but I believe my Gentoo install indicates «Gentoo Linux».

Some tools can be indicative of the distribution, such as apt-get, rpm, emerge, but you can usually install those tools on other distributions as well.

Читайте также:  Linux где папка www

Источник

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.

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.

Источник

How to Find Which Linux Version You Are Running

Logged in on a Linux system via SSH and wondering which Linux distribution is it? Here’s how to check the Linux version.

Читайте также:  Tar to tgz linux

When you install a Linux distribution on your own, you know which distribution and version it is.

But if you use SSH to log in to a remote Linux server provided by an enterprise or client, you may wonder which Linux distribution and version it is.

The simplest way to check Linux version is to see the content of the /etc/os-release file:

It will show an output similar to this:

NAME="Ubuntu" VERSION="20.04.1 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.1 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal

As you can see, the Linux name is Ubuntu and the version is 20.04.1.

However, that’s not the only way to know the Linux distribution details. In this beginner’s tip, I’ll show you different ways to check which Linux you are running.

Find Linux distribution details

How to check Linux version

Method 1: Use /etc/os-release file

If you are familiar with the Linux directory structure, you probably already know that /etc directory contains the core configuration files of the system.

The os-release file in the /etc directory keeps the information about the Linux distribution. It gives you the distribution name, distribution version, release name or ID.

Here’s what it displays for Alpine Linux server running on Linode infrastructure.

handbook:~# cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.12.0 PRETTY_NAME="Alpine Linux v3.12" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://bugs.alpinelinux.org/"

As you can see, the name of Linux distribution is Alpine Linux and the distribution version is 3.12.

The content of the /etc/os-release is usually different for different distributions. Distributions often use it to provide additional information like where to get support or file bugs etc.

For example, the /etc/os-release provides more lines for CentOS Linux.

NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="8" 

However, all of them provide the Linux distribution name and version so it is a pretty reliable way to know which Linux you are running. In fact, it is the most reliable way.

Method 2: Use hostnamectl command

Most Linux distributions these days use systemd. On such a system, you can use the hostnamectl command to get Linux version detail.

For the same CentOS system that you saw above, hostnamectl provides the following details:

[[email protected] ~]# hostnamectl Static hostname: localhost.localdomain Transient hostname: li2498-99.members.linode.com Icon name: computer-vm Chassis: vm Machine ID: e3fe2be3e17be3e1763bf43e8337e68b Boot ID: 33d3052bbffd44b1869bbffd4b00d26c Virtualization: kvm Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-147.8.1.el8_1.x86_64 Architecture: x86-64

You can see the Linux version detail in the line starting with ‘Operating System’.

The hostnamectl command is primarily used for dealing with the hostname but if it provides other details why not use it?

Читайте также:  Application logs in linux

Method 3: Use lsb-release command

This is NOT a command that you’ll find in all Linux distributions. I think it is mostly used by Debian/Ubuntu based distributions.

You can use the lsb_release command with option -a and it will provide distribution details:

Don’t mind the No LSB modules are available line. It’s not an error of any kind.

[email protected]:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal

Bonus Tip: Find Linux kernel version

Now that you know which distribution you are running, perhaps you would also like to know about the Linux kernel version running on the system.

You can get the kernel details using the uname command in any Linux distribution.

The output shows only the Linux kernel version:

handbook:~# uname -r 5.4.43-1-virt

No prizes for guessing that the above system is running on Linux kernel version 5.4.43.

I hope you find this quick tip helpful in finding Linux version detail. If you have questions or suggestions, please let me know in the comment section.

Источник

How do I identify which Linux distro is running? [duplicate]

We have some new hardware in our office which runs its own customized Linux OS. How do I go about figuring which distro it’s based on?

3 Answers 3

A question very close to this one was posted on Unix.Stackexchange HERE Giles has a pretty complete | cool answer for the ways he describes.

# cat /proc/version Linux version 2.6.32-71.el6.x86_64 (mockbuild@c6b6.centos.org) (gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) ) #1 SMP Fri May 20 03:51:51 BST 2011 
# uname -a Linux system1.doofus.local 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/issue CentOS Linux release 6.0 (Final) Kernel \r on an \m 

cat /proc/config.gz cat /usr/src/linux/config.gz cat /boot/config*

Though I did some checking and this was not very reliable except on SUSE.

# zcat /proc/config.gz | grep -i kernel CONFIG_SUSE_KERNEL=y # CONFIG_KERNEL_DESKTOP is not set CONFIG_LOCK_KERNEL=y
  • Novell SuSE—> /etc/SuSE-release
  • Red Hat—>/etc/redhat-release, /etc/redhat_version
  • Fedora—>/etc/fedora-release
  • Slackware—>/etc/slackware-release, /etc/slackware-version
  • Old Debian—>/etc/debian_release, /etc/debian_version
  • New Debian—>/etc/os-release
  • Mandrake—>/etc/mandrake-release
  • Yellow dog—>/etc/yellowdog-release
  • Sun JDS—>/etc/sun-release
  • Solaris/Sparc—>/etc/release
  • Gentoo—>/etc/gentoo-release

There is also a bash script at the Unix.com link someone wrote to automate checking.

Figuring out what package manager you have is a good clue.

rpm yum apt-get zypper +many more

Though this is by no means foolproof as the vendor could use anything they want. It really just gives you a place to start.

# dmesg | less Linux version 2.6.32.12-0.7-default (geeko@buildhost) (gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) ) #1 SMP 2010-05-20 11:14:20 +0200

pretty much the same information as cat /proc/version & uname

Источник

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