Linux system version command

Best way to find the OS name and version on a Unix/Linux platform

But it does not seem to be the best solution, as LSB_RELEASE support is no longer for RHEL 7.

Is there a way that will work on any Unix or Linux platform?

uname is in most unix environments and guaranteed to be on every LSB compliant linux distro: refspecs.linuxfoundation.org/LSB_2.0.1/LSB-Core/LSB-Core/…

@Niraj — By reading the manpage linux.die.net/man/1/uname and grokking its output (assuming it is supported in RH6.5) . either way there is no (single) portable way to get this because it is mostly irrelevant info. Portable programs should probe for required features, not use some whitelist of prechecked distros.

10 Answers 10

This work fine for all Linux environments.

$ cat /etc/*-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04 DISTRIB_CODENAME=lucid DISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS" 
$ cat /etc/*-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS" NAME="Ubuntu" VERSION="12.04.4 LTS, Precise Pangolin" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu precise (12.04.4 LTS)" VERSION_ID="12.04" 
$ cat /etc/*-release Red Hat Enterprise Linux Server release 6.5 (Santiago) Red Hat Enterprise Linux Server release 6.5 (Santiago) 
#!/bin/sh # Detects which OS and if it is Linux then it will detect which Linux # Distribution. OS=`uname -s` REV=`uname -r` MACH=`uname -m` GetVersionFromFile() < VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // ` >if [ "$" = "SunOS" ] ; then OS=Solaris ARCH=`uname -p` OSSTR="$ $($ `uname -v`)" elif [ "$" = "AIX" ] ; then OSSTR="$ `oslevel` (`oslevel -r`)" elif [ "$" = "Linux" ] ; then KERNEL=`uname -r` if [ -f /etc/redhat-release ] ; then DIST='RedHat' PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//` REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` elif [ -f /etc/SuSE-release ] ; then DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//` REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //` elif [ -f /etc/mandrake-release ] ; then DIST='Mandrake' PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//` REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//` elif [ -f /etc/debian_version ] ; then DIST="Debian `cat /etc/debian_version`" REV="" fi if [ -f /etc/UnitedLinux-release ] ; then DIST="$[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]" fi OSSTR="$ $ $($ $ $)" fi echo $

The script is useful but for linux it is showing ==Linux RedHat version(Final 2.6.32-431.el6.x86_64 x86_64) .my redhat version is 6.5 but it is not showing in output ?

I tested on RHEL6.3 It is showing output as Linux RedHat 6.3(Santiago 2.6.32-279.22.1.el6.x86_64 x86_64)

Following command worked out for me nicely. It gives you the OS name and version.

The «lsb_release» command provides a certain Linux Standard Base (LSB) and distribution-specific information.

So using the below command we can get the Operating system name and operating system version.

«lsb_release -a«

This command gives you a description of your operating system:

In every distribution, it has different files, so I list the most common ones:

---- CentOS Linux distribution `cat /proc/version` ---- Debian Linux distribution `cat /etc/debian_version` ---- Redhat Linux distribution `cat /etc/redhat-release` ---- Ubuntu Linux distribution `cat /etc/issue` or `cat /etc/lsb-release` 

In the last one, /etc/issue didn’t exist, so I tried the second one and it returned the right answer.

Читайте также:  Зачем powershell в linux

With quotes:

cat /etc/*-release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g' 

Without quotes:

cat /etc/*-release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g' | sed 's/"//g' 

@PeterMortensen in /etc/*-release file original value is stored with double quotes. if you want to save it in database most probably you would want to remove those double quotes as well. 🙂

My own take at @kvivek’s script, with more easily machine parsable output:

#!/bin/sh # Outputs OS Name, Version & misc. info in a machine-readable way. # See also NeoFetch for a more professional and elaborate bash script: # https://github.com/dylanaraps/neofetch SEP="," PRINT_HEADER=false print_help() < echo "`basename $0` - Outputs OS Name, Version & misc. info" echo "in a machine-readable way." echo echo "Usage:" echo " `basename $0` [OPTIONS]" echo "Options:" echo " -h, --help print this help message" echo " -n, --names print a header line, naming the fields" echo " -s, --separator SEP overrides the default field-separator ('$SEP') with the supplied one" ># parse command-line args while [ $# -gt 0 ] do arg="$1" shift # past switch case "$" in -h|--help) print_help exit 0 ;; -n|--names) PRINT_HEADER=true ;; -s|--separator) SEP="$1" shift # past value ;; *) # non-/unknown option echo "Unknown switch '$arg'" >&2 print_help ;; esac done OS=`uname -s` DIST="N/A" REV=`uname -r` MACH=`uname -m` PSUEDONAME="N/A" GetVersionFromFile() < VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // ` >if [ "$" = "SunOS" ] ; then DIST=Solaris DIST_VER=`uname -v` # also: cat /etc/release elif [ "$" = "AIX" ] ; then DIST="$" DIST_VER=`oslevel -r` elif [ "$" = "Linux" ] ; then if [ -f /etc/redhat-release ] ; then DIST='RedHat' PSUEDONAME=`sed -e 's/.*\(//' -e 's/\)//' /etc/redhat-release ` DIST_VER=`sed -e 's/.*release\ //' -e 's/\ .*//' /etc/redhat-release ` elif [ -f /etc/SuSE-release ] ; then DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//` DIST_VER=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //` elif [ -f /etc/mandrake-release ] ; then DIST='Mandrake' PSUEDONAME=`sed -e 's/.*\(//' -e 's/\)//' /etc/mandrake-release` DIST_VER=`sed -e 's/.*release\ //' -e 's/\ .*//' /etc/mandrake-release` elif [ -f /etc/debian_version ] ; then DIST="Debian" DIST_VER=`cat /etc/debian_version` PSUEDONAME=`lsb_release -a 2> /dev/null | grep '^Codename:' | sed -e 's/.*[[:space:]]//'` #elif [ -f /etc/gentoo-release ] ; then #TODO #elif [ -f /etc/slackware-version ] ; then #TODO elif [ -f /etc/issue ] ; then # We use this indirection because /etc/issue may look like # "Debian GNU/Linux 10 \n \l" ISSUE=`cat /etc/issue` ISSUE=`echo -e "$" | head -n 1 | sed -e 's/[[:space:]]\+$//'` DIST=`echo -e "$" | sed -e 's/[[:space:]].*//'` DIST_VER=`echo -e "$" | sed -e 's/.*[[:space:]]//'` fi if [ -f /etc/UnitedLinux-release ] ; then DIST="$[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]" fi # NOTE `sed -e 's/.*(//' -e 's/).*//' /proc/version` # is an option that worked ~ 2010 and earlier fi if $PRINT_HEADER then echo "OS$Distribution$Distribution-Version$Pseudo-Name$Kernel-Revision$Machine-Architecture" fi echo "$$$$$$$$$$$" 

NOTE: Only tested on Debian 11

Example Runs

No args

Linux,Debian,10.0,buster,4.19.0-5-amd64,x86_64 

Header with names and custom separator

OS | Distribution | Distribution-Version | Pseudo-Name | Kernel-Revision | Machine-Architecture Linux | Debian | 10.0 | buster | 4.19.0-5-amd64 | x86_64 

Filtered output

Источник

How to Check the OS Version in Linux

“Do you know what version of the operating system you have? The administrators and even normal Linux users should know the OS version they are using. It can be useful in various scenarios, such as installing a new application that needs a particular OS version, upgrading the system, checking the availability of various features and troubleshooting issues. Luckily, every Linux distribution lets you check the OS version through multiple ways. This article will describe how you can check the OS version in Linux through both the command-line and the graphical ways.”

Читайте также:  Linux top one time

Note: We have demonstrated the methods discussed here on Debian 11. The command line method is applicable to all Linux distributions. However, the graphical method will only apply to those systems with GUI installed.

Check OS Version via Command-Line Terminal

In this section, we will discuss some command line ways to check the OS version in a Linux OS. These commands work for all Linux distributions.

You can open the Terminal by pressing the super key on your keyboard and then search for it using the search box at the top. When the Terminal icon appears, click on it to open.

Using the lsb_release Command

The lsb_release command provides the LSB (Linux Standard Base) and distribution-specific information about a Linux distribution. The information comprises of distributor ID, release number, codename, and a brief description. The lsb_release command may not be installed in some Linux versions due to minimal OS installation or another issue. In this case, if you try to run the lsb_release command, you will get the “No LSB modules are available” error.

To install lsb_release, open the Terminal and run the command below based on the Linux distribution you have:

For Ubuntu and Debian

For Fedora, CentOS, and RHEL

For Arch Linux and Manjaro

For openSUSE

Once installed, use the command below to check your Linux OS version:

Your system will display an output similar to the one in the image below. It will display the LSB info particular to your Linux distribution, including your Linux system version, which in our case is Debian 11.

To just display the description that shows the OS version, use the lsb_release command with the -d option:

It will just display the description line of the lsb_release output showing the version number.

Using /etc/issue File

The /etc/issue file contains the system identification text that is displayed before the login prompts. To check your Linux OS version, run the command below:

This command shows the version of your Linux OS. To check the OS version with the point releases, run the command below:

Using /etc/os-release File

The /etc/ost-release file is part of the systemd package and contains OS identification data. You can find this command in every latest Linux distribution, particularly in the systemd distributions. You can also find out the version information of your OS using this file.

To view the content of the /etc/os-release file, use the command below:

Using hostnamectl Command

The hostnamectl command is also a part of the systemd package. Generally, this command is used to check and configure the hostname. However, you can also use it to check the version of your Linux OS. Similar to the above command, you can also find this command in every latest Linux distribution.

To view your Linux OS version, run the following command in Terminal:

Check Kernel Information

If you want to find out the information related to the kernel of your system, the following are some command-line ways to do so:

Читайте также:  Linux stop process in background

Using uname Command

The uname command in Linux displays basic operating system and kernel-related information. You can find the kernel release using the uname with -r option as follows:

You will receive the output similar to this:

To find the kernel version, use the uname with -v option:

From the above outputs, you can see the kernel release is 5.10.0-14-amd64, whereas the kernel version is #1 SMP Debian 5.10.113-1 (2022-04-29).

Using dmesg Command

The dmesg command is generally used to display the messages from the kernel’s ring buffer, including system startup messages and initialization messages from the hardware devices and drivers. However, it can also be used to check the version of the kernel. To display the kernel information, pipe the dmesg with the grep command as follows:

You will find the Linux kernel release and the version used in your distribution in the output.

Using /proc/version

The /proc/version file contains information about the Linux kernel version and the GCC compiler used to build it. Run the command below to read the kernel information from the /proc/version file:

You will find the Linux kernel release and the version used in your distribution in the output.

Check OS Version in Linux via Graphical User Interface

This method works for most of Linux distributions with GUI. To check your Linux OS version through the graphical user interface, follow the below-given steps:

Step 1: Open your system’s Settings utility. Right-click on your desktop, and from the context menu, select Settings as demonstrated in the following screenshot:

On the other hand, you can also look for the Settings utility from the Applications menu. Press the super key and type settings in the search box that will appear at the top. When the icon of the Settings utility appears, click it.

Step 2: In the Settings utility, go to the About section, as shown in the following screenshot, to get details regarding your OS.

In the About section, you will find the version of your OS, which is Debian 11. Apart from the OS version, you will find some other information as well, such as OS type, memory, processor, graphics, disk capacity etc.

Note: To find out Debian Latest versions, including the old releases, visit the following page:

Knowing your operating system’s version is important so you can install the right version of the software and follow the proper guide if you run into any issues. In this article, we have covered some methods, including both the graphical and the command line, through which you can view the version of OS as well as the version of the kernel you are running on your system. If you know of some other method that we have missed, we would love to know in the comments below!

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

Источник

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