How to find Linux OS name and version? This tutorial we explain all commands to get os name, its version, kernel version and CPU architecture of the hardware. There are lots of Linux distros like Debian, Ubuntu, CentOS, Mint, Arch, Fedora, RHEL and it's very important to know os version while doing OS update or package updates.
Table of Contents
1) Check OS Version from Command line
Open below file using any of your favorite editors
This file will display OS name.
# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
Hostnamectl command introduced with systemd (new versions of centos and ubuntu) which has multiple functions like display hostname and change system name.
# hostnamectl Static hostname: linoxide Icon name: computer-vm Chassis: vm Machine ID: cb018d6767ca4c8983df25647a8794b0 Boot ID: ac9d219352a94cdba47494ebd1f42f5c Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-862.11.6.el7.x86_64 Architecture: x86-64
Version file inside /proc folder also helps to find OS name and kernel version
# cat /proc/version Linux version 3.10.0-862.11.6.el7.x86_64 (email@example.com) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Tue Aug 14 21:49:04 UTC 2018 #
lsb_release displays Linux Standard Base information about your specific Linux distribution. If you get "command not found" and then you need to install lsb-core package.
# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic
2) Find CPU architecture
There are some command which helps you to know if your CPU is 32 bits or 64 bits
Using uname command
To display processor type
uname -p command
$ uname -p x86_64
If the command doesn't work, you can use
uname -a command which gives more information
Using "arch" command
arch command will display the machine architecture.
$ arch x86_64
You can display CPU architecture information with lscpu command
$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3
The result has been truncated. You can see that the output shows the cpu compatibility mode (32 and 64 bits)
You can us
lshw -c command to filter CPU information on the hardware description which will appear
$ lshw -c cpu *-cpu description: CPU product: Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz vendor: Intel Corp. physical id: 33 bus info: cpu@0 version: Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz serial: To Be Filled By O.E.M. slot: U3E1 size: 2973MHz capacity: 3200MHz width: 64 bits
You can the last line width: 64 bits which indicate the type of processor. This command for the moment doesn't work on RedHat based system but only Debian based system.
You can list /proc/cpuinfo content file to check whether you processor is 32 bits or 64 bits. If you want to see if your processor is 64-bit then look for
lm (means Long Mode) in the flags listed in
$ grep -o -w 'lm' /proc/cpuinfo | sort -u lm
3) Check Linux OS type (32 or 64 bits)
How to check OS installed is supporting 64 or 32 bit? Below command helps to determine that.
You can use the getconf command to know whether the kernel is of 32 bit or 64 bit.
$ getconf LONG_BIT 64
For 32 bits system, you will have 32 instead of 64
Uname command has some options which give a special information and we can have some more information as the OS type with
-a option of the command
$ uname -a Linux centos-01 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
In above output x86_64 GNU/Linux indicates that you have a 64bit Linux kernel running. If you see i386/i486/i586/i686 it is a 32 bit kernel.
When you have a 64 bits OS installed, it means that your CPU is 64 bits too and the packages installed will correspond to the same architecture. So we can see the installed package architecture on our system to determine our OS type
$ dpkg --print-architecture amd64
You can understand that the command can be only used on Debian based systems.
Check library files
The libraries installed on an OS help to determinate the type of this one. When you have a 64 bits OS, you will have 64 bits libraries installed too.
$ ls -la / | grep lib lrwxrwxrwx. 1 root root 7 Feb 21 13:38 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Feb 21 13:38 lib64 -> usr/lib64
You can use
yum info to have some information about available packages. It will also print architecture of OS which is compatible with the package
$ yum info nginx | grep -i arch Arch : x86_64
Because our OS is 64 bits, the package is compatible with 64 bits too
It is possible to have the version of your operating system by displaying the OS type
$ echo $HOSTTYPE x86_64
$ echo $MACHTYPE x86_64-redhat-linux-gnu
Query file type
File command determines file type. The result on the output contains your system architecture
$ file /lib/systemd/systemd /lib/systemd/systemd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=8019aadd1f0962539e2f746b044873956ce2e32c, stripped
You can see
ELF 64-bit, X86-64
For non-systemd OS, you can use
$ file /sbin/init
Are you aware of any more commands? Thanks for taking time to read this tutorial and please provide your suggestions and info on the comments section.