What linux version is installed

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:

Читайте также:  Зашифровать мою домашнюю папку linux mint

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.

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

Источник

Читайте также:  Sccm аналог для linux

What version of Linux am I running?

Get these quick commands to figure out what Linux kernel version and distribution your system is running.

Why the operating system matters even more in 2017

Internet Archive Book Images. Modified by Opensource.com. CC BY-SA 4.0

The question «what version of Linux» can mean two different things. Strictly speaking, Linux is the kernel, so the question can refer specifically to the kernel’s version number, or «Linux» can be used more colloquially to refer to the entire distribution, as in Fedora Linux or Ubuntu Linux.

Both are important, and you may need to know one or both answers to fix a problem with a system. For example, knowing the installed kernel version might help diagnose an issue with proprietary drivers, and identifying what distribution is running will help you quickly figure out if you should be using apt , dnf , yum , or some other command to install packages.

The following will help you find out what version of the Linux kernel and/or what Linux distribution is running on a system.

How to find the Linux kernel version

To find out what version of the Linux kernel is running, run the following command:

Alternatively, the command can be run by using the longer, more descriptive, versions of the various flags:

uname --kernel-name --kernel-release --machine

Either way, the output should look similar to the following:

Linux 4.16.10-300.fc28.x86_64 x86_64

This gives you (in order): the kernel name, the version of the kernel, and the type of hardware the kernel is running on. In this case, the kernel is Linux version 4.16.10-300.fc28.x86_64 running on an x86_64 system.

More information about the uname command can be found by running man uname .

How to find the Linux distribution

There are several ways to figure out what distribution is running on a system, but the quickest way is the check the contents of the /etc/os-release file. This file provides information about a distribution including, but not limited to, the name of the distribution and its version number. The os-release file in some distributions contains more details than in others, but any distribution that includes an os-release file should provide a distribution’s name and version.

To view the contents of the os-release file, run the following command:

On Fedora 28, the output looks like this:

NAME=Fedora VERSION="28 (Workstation Edition)" ID=fedora VERSION_ID=28 PLATFORM_ID="platform:f28" PRETTY_NAME="Fedora 28 (Workstation Edition)" ANSI_COLOR="0;34" CPE_NAME="cpe:/o:fedoraproject:fedora:28" HOME_URL="https://fedoraproject.org/" SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Fedora" REDHAT_BUGZILLA_PRODUCT_VERSION=28 REDHAT_SUPPORT_PRODUCT="Fedora" REDHAT_SUPPORT_PRODUCT_VERSION=28 PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy" VARIANT="Workstation Edition" VARIANT_ID=workstation

As the example above shows, Fedora’s os-release file provides the name of the distribution and the version, but it also identifies the installed variant (the «Workstation Edition»). If we ran the same command on Fedora 28 Server Edition, the contents of the os-release file would reflect that on the VARIANT and VARIANT_ID lines.

Читайте также:  Linux mint cinnamon 64 bit iso

Sometimes it is useful to know if a distribution is like another, so the os-release file can contain an ID_LIKE line that identifies distributions the running distribution is based on or is similar to. For example, Red Hat Enterprise Linux’s os-release file includes an ID_LIKE line stating that RHEL is like Fedora, and CentOS’s os-release file states that CentOS is like RHEL and Fedora. The ID_LIKE line is very helpful if you are working with a distribution that is based on another distribution and need to find instructions to solve a problem.

CentOS’s os-release file makes it clear that it is like RHEL, so documentation and questions and answers in various forums about RHEL should (in most cases) apply to CentOS. CentOS is designed to be a near clone of RHEL, so it is more compatible with its LIKE than some entries that might be found in the ID_LIKE field, but checking for answers about a «like» distribution is always a good idea if you cannot find the information you are seeking for the running distribution.

More information about the os-release file can be found by running man os-release .

Screenfetch and neofetch

The uname and /etc/os-release commands are the most common methods for getting the version of Linux you’re running and are available by default on any Linux system you run. There are, however, additional tools that can provide you a report about your system.

The screenfetch and neofetch commands give a verbose overview of your system, with details about your kernel, architecture, available RAM, CPU speed and core count, desktop version, and so on.

Hostnamectl

The hostnamectl command is available on most modern Linux distributions. If it’s not already installed, you can install it from your software repository. Despite its humble name, it provides far more than just your hostname;

$ hostnamectl Static hostname: yorktown.local Icon name: computer-laptop Chassis: laptop Machine ID: 442fd448a2764239b6c0b81fe9099582 Boot ID: a23e2566b1db42ffe57089c71007ef33 Operating System: CentOS Stream 8 CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-301.1.el8.x86_64 Architecture: x86-64 

Desktop utilities

Some desktop environments offer similar system reporting tools. For instance, the KDE Plasma desktop provides KInfoCenter, which can tell you everything from your kernel and architecture to your available network interface cards, IP address, and much more.

KInfoCenter

Know your OS

Regardless of what tool you decide to make your default, getting the version and features of your OS is a seemingly simple but important skill. Remember these tips so the next time you need to see what you’re running, you’ll know several places you can find out.

This article originally published in 2018 and has been updated by the editor with additional information.

Источник

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