Check linux os version from command line

Today, I want to install git on one of the server, but I forget the os version, so I searched how to check linux os version from command…

Check linux os version from command line
Photo by Alex Chumak on Unsplash

Today, I want to install git on one of the server, but I forget the os version, so I searched how to check linux os version from command line, and find the following commands that I can use.

Check by /etc/os-releasecat /etc/os-release

Sample outputNAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

Check by hostnamectlhostnamectl

Sample outputStatic hostname: <hostname>
        Icon name: computer-vm
          Chassis: vm
       Machine ID: fb80ff3d585344ed916505323f431f60
          Boot ID: aaf72b920d6e45b09d8e93a7af4aeee8
   Virtualization: kvm
 Operating System: CentOS Stream 8
      CPE OS Name: cpe:/o:centos:centos:8
           Kernel: Linux 4.18.0-338.el8.x86_64
     Architecture: x86-64

There are also some other commands, but for me, I think both of the above commands is enough for me.

Resources