Linux see system version

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.

Читайте также:  Установка gui astra linux

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.

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

Источник

Читайте также:  Linux mint настройка дисплея

How to Check the Linux OS Version (6 Ways)

Check Linux version

Linux OSes are some of the best replacements for Windows and macOS because they have gotten impressively capable over the years. Not just the Linux kernel but a lot of components like desktop environments and display servers are now more capable than they were before. With too many distro releases, keeping track of Linux versions could be challenging, especially on rolling releases. So, here are six ways to check the Linux OS version easily on your PC.

1. Check Linux Version using lsb_release Command

“LSB” stands for Linux Standard Base and the lsb_release command was specially developed to allow Linux users to check their Linux OS version; that’s all it does. To check the Linux OS version, paste the below command in the terminal and hit enter.

lsb release command Linux

The -a stands for “all” in the command, meaning you are asking the “lsb_release” command to list all the details about your Linux distro. You could also use -d, -r, and -c to find out the description, release, and codename using this command, respectively.

2. Check Linux OS Version using Neofetch

Unlike other commands that only display text, Neofetch is a fancy command that displays the ASCII art of the logo of the distro you are using. In addition to the artwork, it shows everything you would need to know about the distro, including the Linux version, resolution, desktop environment, processor, GPU, and memory. Now, the Neofetch command doesn’t come installed by default, so you will first need to install it.

# For Ubuntu/Debian-based distros sudo apt install neofetch # For Fedora/CentOS sudo dnf install neofetch # For Arch-based distros sudo pacman -S neofetch # For OpenSUSE sudo zypper install neofetch

Once installed, type neofetch in the Linux command line and hit Enter. Here’s what you will see as the output:

neofetch

3. Check Linux Version using Cat Command

The cat command in Linux stands for “concatenate,” and this highly useful Linux command is specifically used to display file contents in the terminal. To get the details about the Linux OS version using the cat command, we need to target the “os-release” text file that resides in the /etc directory inside the root. Here’s how:

Cat command os-release linux

4. Check Linux Version using Uname Command

Most of the aforementioned commands do not display the kernel version. However, if you specifically want to check the kernel version of your Linux OS, uname is the only command you need.

“uname” is short for Unix Name and is specifically meant to display details about Linux desktops. It comes built into Linux, and here is how you use the command:

uname command - check os version in Linux

5. Check Linux Version using Hostnamectl Command

Last but not least command, you can also use the “Hostnamectl” command to find out the Linux OS version. As the name suggests, this command is used to display the hostname of the distro. This command will only work with sudo privileges:

Читайте также:  Linux force fsck on boot

hostnamectl linux

6. GUI Method to Check the Linux OS Version

If you are new to Linux, you probably don’t like the terminal much because it hasn’t grown on you yet. Hence, if you don’t like using the terminal and are looking for a way to find out the Linux version, it’s possible with this GUI method.

1. Go to Settings on your Linux PC.

2. Scroll all the way down and open the “About” section.

3. Here, you should see the details about the installed Linux distro.

Pop!OS about section - check os version linux

Bear in mind that the Settings app on your distro may look vastly different from ours. If you don’t see the “About” section right away, it’s usually located in the settings and you may need to dig a bit deeper.

Frequently Asked Questions

There are different commands like lsb_release, uname, Hostnamectl, cat, and neofetch that you can use to check the current version on Linux OS.

To check the Linux version on Ubuntu, go to the command terminal and execute the “lsb_release” command.

Источник

Linux see system version

How to check Debian version: the quick and easy way

How to check Debian version: the quick and easy way

Knowing which Debian version you have not only helps you to choose the right install package for a program – you also need it to get appropriate support in forums. There are several different methods to check your Debian version. In this step-by-step guide, we’ll explain how to check your version using Terminal and Hardinfo.

How to check your Ubuntu version: a guide

How to check your Ubuntu version: a guide

Knowing which Ubuntu version you’re running is helpful for different things. You can use this information to check whether programs are compatible with your system. Or you can include the version number in troubleshooting searches. It’s thus of crucial importance to know how to check your Ubuntu version. Keep reading to find out how to do so in a few simple clicks.

How to delete a Linux directory

How to delete a Linux directory

Sometimes you may need to delete an entire folder rather than just individual files. If you want to remove a Linux directory, there are several ways to do it. Here are a few basic solutions that use either File Manager or Terminal. We also explain what you can do if you don’t have the necessary rights.

How to delete files in Linux

How to delete files in Linux

Deleting files in Linux couldn’t be easier. Whether you use the file manager or work directly in the terminal with the command “rm”, you can remove Linux files in just a few clicks. Keep reading to find out how to remove single files, multiple files, files of a certain type, or entire folders.

How to use the Linux find command

How to use the Linux find command

While working on a Linux system the command line is frequently used. Many administrative tasks require you to find files and directories based on specific criteria. In doing so, Linux admins are accustomed to using the find command. Here, we’ll show you how the command works and how to use it as a handy tool.

Источник

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