9 Methods to check whether your Linux system is 32-bit or 64-bit

As a server administrator we should be aware of our system architecture which will help us to install a third party software’s accordingly on system.

By default the necessary software get installed from their own repository when we perform installation from package management tools such as yum, dnf, apt-get, zypper & urpmi .But for third party software’s we should know the system architecture to download the necessary archive for perform installation.

We are going to teach you basic/modern commands and some extreme commands to check your Linux system is either 32 bit or 64 bit.

Suggested Read : 16 Methods To Check If A Linux System Is Physical or Virtual Machine

Basically two types of architecture is available for hardware 32-bit & 64-bit but software package has three types of architecture package 32-bit, 64-bit & noarch files. The noarch file will be compatible for both 32 & 64 bit architecture.

In Linux x86_64 indicates that you have a 64-bit Architecture & i386/i486/i586/i686 indicates that you have a 32-bit Architecture.

Method-1 : Using uname Command

uname (stands for unix name) is an utility that prints the system information like name, version and other details about the system and the operating system running on it.

# uname -p
or
# uname -i
or
# uname -m
x86_64

Method-2 : Using arch Command

Print machine hardware name same as (uname -m). We can use arch command as a alternate to get the system OS architecture type.

# arch
x86_64

Method-3 : Using lscpu Command

lscpu – display information on CPU architecture and gathers CPU architecture information like number of CPUs, threads, cores, sockets, NUMA nodes, information about CPU caches, CPU family, model and prints it in a human-readable format.

# 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
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 58
Model name:            Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
Stepping:              9
CPU MHz:               1212.453
CPU max MHz:           3200.0000
CPU min MHz:           1200.0000
BogoMIPS:              5188.18
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3

Alternately use the lscpu command to print only architecture information.

# lscpu | grep Architecture | awk '{print $2}'
x86_64

Method-4 : Using lshw Command

lshw – list hardware. lshw is a small tool to extract detailed information on the hardware configuration of the machine. We can use lshw command as a alternate to get the system OS architecture type.

# lshw -class cpu
or
# lshw -class processor
  *-cpu                   
       product: Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
       vendor: Intel Corp.
       physical id: 1
       bus info: cpu@0
       size: 1320MHz
       capacity: 3200MHz
       width: 64 bits
       capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp x86-64 constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt cpufreq

Alternately use the lshw command to print only architecture information.

# lshw -class cpu | grep width | awk '{print $2, $3}'
64 bits

Method-5 : Using getconf Command

getconf stands for get configuration values. getconf utility used to write the value of the variable specified by the system_var & path_var operand. The value of each configuration variable were obtained from IEEE Std 1003.1-2001

# getconf LONG_BIT
64

Method-6 : Using environment variable

An environmental variable pointing to a Bash startup file to be read when a script is invoked. It identifies the system hardware.

# echo $MACHTYPE
x86_64-redhat-linux-gnu

or

# echo $HOSTTYPE
x86_64

Method-7 : Using file Command

file command determine file type. It performs three type of tests to identify a file type like file system tests, magic tests, and language tests.

If the file contains only printing characters which can be readable by human & other files like executable, binary, or non-printable, etc, can be readable by kernel or other programs.

On SysVinit System

# file /sbin/init
/sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

[Alternatively print only Architecture]
# file /sbin/init | awk '{print $3}'
64-bit

[Alternatively print only Architecture]
# file /sbin/init | awk '{print $7}' | sed 's/.$//'
x86-64

On systemd System

# file /lib/systemd/systemd
/lib/systemd/systemd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=832cea0e7a1230fd7ebf93bba1858888ecb9b4d1, stripped

[Alternatively print only Architecture]
# file /sbin/init | awk '{print $3}'
64-bit

[Alternatively print only Architecture]
# file /sbin/init | awk '{print $7}' | sed 's/.$//'
x86-64

Using /usr/bin/id binary file

# file /usr/bin/id
/usr/bin/id: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=1c6631a8f19b025c9e4da1456a9514111425870d, stripped

[Alternatively print only Architecture]
# file /usr/bin/id | awk '{print $3}'
64-bit

[Alternatively print only Architecture]
# file /usr/bin/id | awk '{print $6}' | sed 's/.$//'
x86-64

Using /sbin/arp binary file

# file /sbin/arp
/sbin/arp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

[Alternatively print only Architecture]
# file /sbin/arp | awk '{print $3}'
64-bit

[Alternatively print only Architecture]
# file /sbin/arp | awk '{print $6}' | sed 's/.$//'
x86-64

Using /usr/bin/file binary file

# file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

[Alternatively print only Architecture]
# file /usr/bin/file | awk '{print $3}'
64-bit

[Alternatively print only Architecture]
# file /usr/bin/file | awk '{print $6}' | sed 's/.$//'
x86-64

Method-8 : Using dpkg Command

dpkg stands for Debain Package manager, It is a tool to install, build, upgrade, remove and manage packages to Debain based systems such as Ubuntu, LinuxMint, elementryOS, etc.,. We can use dpkg command as a alternate to get the system OS architecture type only for Debian based systems.

# dpkg --print-architecture
amd64

Method-9 : Using /proc/cpuinfo file

/proc/cpuinfo is a virtual text file that contains information about the CPUs (central processing units) on a computer. We can get a system OS architecture by grepping lm: Long Mode parameter Under “flags”. flags Defines a number of different qualities about the processor.

  • lm flag stands Long mode cpu : 64-bit CPU
  • tm flag stands Protected mode : 32-bit CPU
  • rm flag stands Real Mode : 16-bit CPU
# grep flags /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc up rep_good unfair_spinlock pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm xsaveopt tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 avx2 smep bmi2 erms invpcid

3 Comments on “9 Methods to check whether your Linux system is 32-bit or 64-bit”

  1. Most of these are not really correct. They show what the CPU support or what kind of kernel is being used. It’s not uncommon to have a 32-bit system running on a 64-bit Linux kernel. It’s important to realize that these 9 methods are not really saying the same thing.

  2. Just sayin’, ‘yum info httpd’ will only give interesting output if apache is installed. Even if apache is installed, it is possible to install the 32-bit version of apache on a 64-bit system and then this will give the wrong answer. Similarly, using dpkg under a Debian-based OS as you describe will only print the architectures that dpkg has been told to use. With multi-arch support enabled, this ‘dpkg –print-architecture’ will print a list of enabled architectures for the system. This list will not necessarily include the native architecture. Therefore this, too, is a completely useless command for determining anything about the processor!

Leave a Reply

Your email address will not be published. Required fields are marked *