How to get Linux version from the command line


Given a minimum version of Linux, how do you know which distribution and distro are being used? This is a crucial issue. First, you might consider typing uname -a, but that doesn’t provide all the information you might need. Fortunately, almost all distributions have a file that holds this valuable data.

This is the / etc / os-release file. You might guess how to check it, because we have already introduced the use of the cat command before. So all you need to do is happily have what you need.

$ cat /etc/os-release
VERSION="18.04.2 LTS (Bionic Beaver)"
PRETTY_NAME="Ubuntu 18.04.2 LTS"

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

  • -a, -all All information is printed in the following order, except -p and -i are omitted (if unknown):
  • -s,-kernel name Print kernel name
  • -n, –nodename Print network node hostname
  • -r, – kernel release Print kernel version
  • -v,-kernel version Print kernel version
  • -m, -machine Printer hardware name
  • -p, -processor Print processor type (non-portable)
  • -i, – hardware platform Printing hardware platform (non-portable)
  • -Version Output uname version information and exit
  • -o,-operating system (Mainly output GNU / Linux)

Examples of consistent usage

$ uname -o                                                                                                    

$ uname -m                                                                                                    

$ uname -r

$ uname -s                                                                                                    

$ 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 uname command cannot be used to find the release and release.

Use lsb_release command

On Debian-based Linux distributions, you can use the lsb_release command to print release-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 usage examples 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

Use hostnamectl command

For Linux systems with Systemd init, you can get some system information from the hostnamectl command output, such as 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 full list of available options below:

$ 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

  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

Look at the content on / etc / issue.

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

in conclusion

Finding releases and releases is easy. We hope it is useful and useful.

Also read:

How to check CPU usage / utilization in Linux systems

How to use Linux find command to locate files

How to set up a system-wide proxy on Ubuntu 18.04 / Debian 10

How to set up Squid proxy on Ubuntu 18.04 / Ubuntu 16.04 / CentOS 7

Grafana behind Nginx and Apache Proxy