Linux command to return number of bits (32 or 64)?
What is a Linux command that I can run to programmatically return either 32 or 64 to indicate whether the processor is a 32 bit or 64 bit processor?
-
You can see whether the CPU is 64-bit, 32-bit, or capable of both by checking the
flags
line in/proc/cpuinfo
. You have to know the possible flags on your architecture family. For example, on i386/amd64 platforms, thelm
flag identifies amd64-capable CPUs (CPUs that don't have that flag are i386-only).grep -q '^flags\s*:.*\blm\b' /proc/cpuinfo # Assuming a PC
-
You can see whether the kernel is 32-bit or 64-bit by querying the architecture with
uname -m
. For example,i[3456]86
are 32-bit whilex86_64
is 64-bit. Note that on several architectures, a 64-bit kernel can run 32-bit userland programs, so even if theuname -m
shows a 64-bit kernel, there is no guarantee that 64-bit libraries will be available.[ "$(uname -m)" = "x86_64" ] # Assuming a PC
Note also that
uname -m
may return a “virtualized” value. For example, under Linux, if you runsetarch i386 bash
on an amd64 system, and you rununame -m
from that bash, you'll seeuname -m
reportingi386
. This effectively lets you pretend that you're on a “32-bit system” even though the kernel is a 64-bit one, for example to compile 32-bit programs without setting up cross-compilation. You can see what is available in userland by querying the LSB support with the
lsb_release
command. More precisely,lsb_release -s
prints a:
-separated list of supported LSB features. Each feature has the formmodule-version-architecture
. For example, availability of an ix86 C library is indicated bycore-2.0-ia32
, whilecore-2.0-amd64
is the analog for amd64. Not every distribution declares all the available LSB modules though, so more may be available than is detectable in this way.You can find out the preferred word size for development (assuming a C compiler is available) by compiling a 5-line C program that prints
sizeof(void*)
orsizeof(size_t)
.
You can use uname -a
and look for x86_64
to see if you are running 64-bit. Anything else (As far as I know) and you are running 32-bit or you are on non-PC hardware such as alpha
, sparc
, or ppc64
.
uname -m | sed 's/x86_//;s/i[3-6]86/32/'
getconf uses the fewest system calls:
$ strace getconf LONG_BIT | wc -l
253
$ strace arch | wc -l
280
$ strace uname -m | wc -l
281
$ strace grep -q lm /proc/cpuinfo | wc -l
301
Type:
uname -a
If you get x86_64 GNU/Linux
you're running a 64 bit kernel. If you get something similar to i386/i486/i586/i686
you're most probably running a 32 bit kernel