How to get Linux version from the command line

Cpanel/Whm License $3/mo Plesk License $10/mo Cloudlinux License $5/mo

(: July 31, 2019)

Introduction

Given a minimal version of a Linux system, how can you know which distribution and which version of the distribution you are working on? This is a vital question. First, you may think about typing in uname -a, but this does not provide all of the information you may need. Luckily, there is a file that almost all distributions have that keeps this valuable data.

This is the /etc/os-release file. You might guess how it can be viewed because we covered the use of cat command previously. So, you simply do the following and you will happily have what you are looking for.

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
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=bionic
UBUNTU_CODENAME=bionic

uname, on the other hand, provides the following system information:

.td_uid_2_5d908cde6ea83_rand.td-a-rec-img{text-align:left}.td_uid_2_5d908cde6ea83_rand.td-a-rec-img img{margin:0 auto 0 0}
  • -a, –all print all information, in the following order, except omit -p and -i if unknown:
  • -s, –kernel-name print the kernel name
  • -n, –nodename print the network node hostname
  • -r, –kernel-release print the kernel release
  • -v, –kernel-version print the kernel version
  • -m, –machine print the machine hardware name
  • -p, –processor print the processor type (non-portable)
  • -i, –hardware-platform print the hardware platform (non-portable)
  • –version output uname version information and exit
  • -o, –operating-system (mostly outputs GNU/Linux)

Examples of uname usage

$ uname -o                                                                                                    
GNU/Linux

$ uname -m                                                                                                    
 x86_64

$ uname -r
 4.15.0-54-generic

$ uname -s                                                                                                    
 Linux

$ uname -a
 Linux cloudstack 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

As you can see above, the distribution and version of the distribution cannot be found using the uname command.

Using lsb_release command

On Debian based Linux distributions, you can use the lsb_release command to print distribution-specific information.

Available options:

-v, --version: Show the version of the LSB against which your current installation is compliant.
-i, --id:  Display the distributor's ID.
-d, --description: Display a description of the currently installed distribution.
-r, --release: Display the release number of the currently installed distribution.
-c, --codename: Display the code name of the currently installed distribution.
-a, --all: Display all of the above information.
-s, --short: Use the short output format for any information displayed.  This format omits the leading header(s).
-h, --help: Show summary of options.

See examples on usage below.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

$ lsb_release -c
Codename:	buster

$ lsb_release -d
Description:	Debian GNU/Linux 10 (buster)

$ lsb_release -i
Distributor ID:	Debian

Using hostnamectl command

For Linux systems with Systemd init, you can get some system information from hostnamectl command output, like the Operating System, Kernel version and CPU architecture.

[email protected]:~# hostnamectl 
    Static hostname: debian10
          Icon name: computer-vm
            Chassis: vm
         Machine ID: 2e5ced54e5274424b2165b459a18372a
            Boot ID: e21975d65c53409497466bfbce9cc193
     Virtualization: kvm
   Operating System: Debian GNU/Linux 10 (buster)
             Kernel: Linux 4.19.0-5-amd64
       Architecture: x86-64

See the complete list of available options with:

$ hostnamectl  --help
hostnamectl [OPTIONS...] COMMAND ...

Query or change system hostname.

  -h --help              Show this help
     --version           Show package version
     --no-ask-password   Do not prompt for password
  -H --host=[[email protected]]HOST  Operate on remote host
  -M --machine=CONTAINER Operate on local container
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname

Commands:
  status                 Show current hostname settings
  set-hostname NAME      Set system hostname
  set-icon-name NAME     Set icon name for host
  set-chassis NAME       Set chassis type for host
  set-deployment NAME    Set deployment environment for host
  set-location NAME      Set location for host

See the hostnamectl(1) man page for details.

Check /etc/issue Content

View content on /etc/issue.

$ cat /etc/issue
Debian GNU/Linux 10 n l

Conclusion

Finding the distribution and version of the distribution is as easy as you have found out. We hope it was beneficial and informative.

Also Read:

How To Check CPU Usage/Utilization in Linux system

How To Use Linux find Command To Locate files

How To Set System-Wide Proxy on Ubuntu 18.04 / Debian 10

How to setup Squid proxy on Ubuntu 18.04 / Ubuntu 16.04 / CentOS 7

Grafana behind Nginx and Apache Proxy

.td_uid_4_5d908cde6ec8f_rand.td-a-rec-img{text-align:left}.td_uid_4_5d908cde6ec8f_rand.td-a-rec-img img{margin:0 auto 0 0}

Related posts

How To Add RHEL 8 qcow2 Image To OpenStack Glance

SXI ADMIN

Microsoft CEO Challenges Swift: Build ‘Useful’ Blockchain Applications

SXI ADMIN

Bitcoin Exchange Gemini Adds APIs for Automated Traders

SXI ADMIN

How To Install MariaDB 10.3 on openSUSE 15

SXI ADMIN

The World Economic Forum Might Not Be Ready to Lead a Blockchain Revolution

SXI ADMIN

Butterfly Labs Resumes Shipping, Sets Timetable for Refunds

SXI ADMIN

ECB Official Calls Bitcoin ‘Evil Spawn of the Financial Crisis’

SXI ADMIN

Moscow Government to Explore Blockchain Voting

SXI ADMIN

Scams, Hacks and Poor Management: Life After Silk Road

SXI ADMIN

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More