Which operating system linux command line

How to know if the running platform is Ubuntu or CentOS with help of a Bash script?

How do I get the output from the terminal and compare to see if it is UBUNTU or CENTOS and perform the following commands?

Ubuntu 14.04

14 Answers 14

Unfortunately, there is no surefire, simple way of getting the distribution name. Most major distros are moving towards a system where they use /etc/os-release to store this information. Most modern distributions also include the lsb_release tools but these are not always installed by default. So, here are some approaches you can use:

# Determine OS platform UNAME=$(uname | tr "[:upper:]" "[:lower:]") # If Linux, try to determine specific distribution if [ "$UNAME" == "linux" ]; then # If available, use LSB to identify distribution if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then export DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//) # Otherwise, use release info file else export DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1) fi fi # For everything else (or if above failed), just use generic identifier [ "$DISTRO" == "" ] && export DISTRO=$UNAME unset UNAME 
$ gcc --version gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54) Copyright (C) 2006 Free Software Foundation, Inc. 
$ gcc --version gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) Copyright (C) 2010 Free Software Foundation, Inc. 
$ gcc --version gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Copyright (C) 2011 Free Software Foundation, Inc. 
$ gcc --version gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

This has basically been directly copied from @slm’s great answer to my question here.

Источник

How to Find Linux OS Name and Kernel Version You Are Running

There are several ways of knowing the version of Linux you are running on your machine as well as your distribution name and kernel version plus some extra information that you may probably want to have in mind or at your fingertips.

Therefore, in this simple yet important guide for new Linux users, I will show you how to find out your Linux system OS version from the command line. Doing this may seem to be a relatively easy task.

Читайте также:  Узнать модель процессора линукс

However, having a good knowledge of your system is always a recommended practice for a good number of reasons including installing and running the appropriate packages for your Linux version, for easy reporting of bugs coupled with many more.

With that said, let us proceed to how you can figure out information about your Linux distribution.

Find Linux Kernel Version Using uname Command

We will use the uname command, which is used to print your Linux system information such as kernel version and release name, network hostname, machine hardware name, processor architecture, hardware platform, and the operating system.

To find out which version of Linux kernel you are running, type:

In the preceding command, the option -o prints the operating system name, and -r prints the kernel release version.

You can also use -a option with uname command to print all system information as shown:

Check Linux Kernel Version

Find Linux OS Info Using /proc/version File

Next, we will use /proc file system, which stores information about processes and other system information, it’s mapped to /proc and mounted at boot time.

Simply type the command below to display some of your system information including the Linux kernel version:

Show Linux System Information

From the image above, you have the following information:

  • A version of the Linux (kernel) you are running: Linux version 5.15.0-53-generic
  • Name of the user who compiled your kernel: [email protected]
  • A version of the GCC compiler used for building the kernel: gcc version 20.04.1
  • Type of the kernel: #1 SMP (Symmetric MultiProcessing kernel) supports systems with multiple CPUs or multiple CPU cores.
  • Date and time when the kernel was built: Thu Oct 20 15:10:22 UTC 2022

Find the Linux Distribution Name and Release Version

The best way to determine a Linux distribution name and release version information is by using the cat /etc/os-release command, which works on almost all Linux systems.

/etc/os-release file

$ cat /etc/os-release [On Debian, Ubuntu and Mint] $ cat /etc/os-release [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ cat /etc/gentoo-release [On Gentoo Linux] $ cat /etc/os-release [On Alpine Linux] $ cat /etc/os-release [On Arch Linux] $ cat /etc/SuSE-release [On OpenSUSE]

Find Linux Distribution Name and Release

lsb_release Command

Alternatively, you can also use the lsb_release tool, which will print LSB (Linux Standard Base) information about the Linux distribution on your terminal. The lsb_release command is not installed by default, you need to install it using your default package manager as shown.

$ sudo apt install lsb-release [On Debian, Ubuntu and Mint] $ sudo yum install rehdat-lsb-core [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/lsb-release [On Gentoo Linux] $ sudo apk add lsb_release [On Alpine Linux] $ sudo pacman -S lsb-release [On Arch Linux] $ sudo zypper install lsb-release [On OpenSUSE]

Once installed, run the lsb_release utility to print the standard Linux system information as shown.

Читайте также:  Linux how to connect wifi with password

Find Linux OS Information

hostnamectl Command

The hostnamectl command is a systemd utility that is used to get the Linux operating system information and also used to change or set the system hostname.

Check Linux System Info

I’ve used the tmux terminal multiplexer for accessing multiple Linux terminal sessions simultaneously in a single terminal window.

In this article, we walked through a brief and simple guide intended to help new Linux users find out the Linux version they are running and also get to know their Linux distribution name and version from the shell prompt.

Perhaps it can also be useful to advanced users on one or two occasions. Lastly, to reach us for any assistance or suggestions you wish to offer, make use of the feedback form below.

Источник

How To Find Linux OS Distribution and Version?

How To Find Linux OS Distribution and Version?

Linux is a free and open-source operating system. A lot of distributions and versions are created on the Linux kernel. Even all of them are called Linux they have specific names and versions like Ubuntu 20.04, Debian 11, RHEL 8, etc. While working with Linux knowing the distributions and version is very important. Especially while using the command line or bash shell the commands and configuration supported current Linux is important. In this tutorial, we will learn how to list or display current Linux distributions, version, and Linux kernel version.

List Distribution and Versions with lsb_release Command

The lsb_release is a very popular command which is provided by most Linux distributions. The lsb_release command can be used in Ubuntu, Debian, Mint, Kali, Fedora, CentOS, Rocky Linux, RHEL, SUSE etc. The -a option should be provided to the lsb_release command in order to list current distribution name and version.

The output is like below which contains distribution ID, description, release number which can be also called as version and the codename. Codename is used by some Linux distributions in order to name different versions. We can see that current distributions name is “Ubuntu” and version is “20.10”.

Distributor ID: Ubuntu Description: Ubuntu 20.10 Release: 20.10 Codename: groovy

List Distribution and Versions with /etc/os-release File

Some linux distirbutions like Debian, Ubuntu stores the current distributions name and version information in the file named “/etc/os-release”. This file contains detailed information which can be printed to the terminal by using the cat command like below.

We can see that following information about the distributions and version is provided.

  • NAME: The distributions name which is “Ubuntu” in this example.
  • VERSION: The version of the distribution which is 20.10 in this example.
  • ID: The distribution canonical name which is “ubuntu” in this example.
  • ID_LIKE: The distribution source where “debian” is the source of the Ubuntu.
  • PRETTY_NAME: The distribution human friendly complete name with the distribution name and version.
  • VERSION_ID: The distribution version which is “20.10”.
  • HOME_URL: The distribution official web site URL which is “https://www.ubuntu.com/” in this case.
  • VERSION_CODENAME: This is version code name which is “groovy” in this example.
  • UBUNTU_CODENAME: This is ubuntu version code name which is “groovy” in this example.
NAME="Ubuntu" VERSION="20.10 (Groovy Gorilla)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.10" VERSION_ID="20.10" 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=groovy UBUNTU_CODENAME=groovy

If we need to list only the Linux os name and version the grep command can be used to filter the output like below.

grep "^PRETTY_NAME" /etc/os-release

If we want only list the operating system name the following command can be used.

Читайте также:  Git configuration in linux

Only distribution version can be printed by grepping the VERSION_ID line like below.

grep "^VERSION_ID" /etc/os-release

Alternatively a text editor can be used to view the current Linux os distribution name and version via the desktop environment.

List Distribution and Versions with hostnamectl Command

The hostnamectl command is used to manage, list, change the hostname and related information. but it can be also used to list the Linux OS name with the version information. Just run the hostnamectl command which will list the Operating System line with the distribution name and version. Also the Kernel line provides the currently installed and running kernel version.

Static hostname: ubuntu Icon name: computer-vm Chassis: vm Machine ID: 295c2cf105a140e5ab505a9e74ff560e Boot ID: ac4b559e8d414569816cd76c3e330727 Virtualization: vmware Operating System: Ubuntu 20.10 Kernel: Linux 5.8.0-45-generic Architecture: x86-64

If you just want to list distribution name and version the grep command can be used filter the “Operating System:” line like below.

hostnamectl | grep "Operating System" 
Operating System: Ubuntu 20.10

List Distribution and Versions with uname Command

The uname command can be also used to list Linux distribution OS names. The -a option should be provided to list all information about the system. This command does not provide the distribution version but lists the kernel version.

Linux ubuntu 5.8.0-45-generic #51-Ubuntu SMP Fri Feb 19 13:24:51 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

List Distribution and Versions with /proc/version File

The /proc/ directory contains information about the system and low level operations and functions. The /proc/version can be used to list current distribution name but the version information is not provided.

Linux version 5.8.0-45-generic (buildd@lcy01-amd64-010) (gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0, GNU ld (GNU Binutils for Ubuntu) 2.35.1) #51-Ubuntu SMP Fri Feb 19 13:24:51 UTC 2021

List Distribution and Versions with /etc/issue File

The /etc/issue file only contains the current Linux distribution name and version. This is very simple file and can be listed with the cat command.

List Distribution and Versions by Connection SSH

Even this is not a practical way to display the current Linux distribution name and version it can be used for different cases. When we login to the Linux system with the SSH protocol the current distribution name and version are listed below. In the following example, the Linux OS name is Ubuntu and the version is 20.10.

Источник

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