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.
grep "^NAME" /etc/os-release
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"
The output is like below.
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 ([email protected]) (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.
Ubuntu 20.10 \n \l
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.