Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
@Sathya: That's not exactly a duplicate, because the processor can be 64-bit even if the Linux isn't. – Gilles Nov 8 '10 at 0:07
up vote 12 down vote accepted
  • 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, the lm 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 while x86_64 is 64-bit. Note that on several architectures, a 64-bit kernel can run 32-bit userland programs, so even if the uname -m shows a 64-bit kernel, there is no guarantee that 64-bit libraries will be available.

    [ "$(uname -m)" = "x86_64" ]    # Assuming a PC
  • 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 form module-version-architecture. For example, availability of an ix86 C library is indicated by core-2.0-ia32, while core-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*) or sizeof(size_t).

share|improve this answer
On GNU systems (and others if they have it), you should be able to do getconf WORD_BIT or getconf LONG_BIT instead of having to compile your own C program (trivial, and portable, though it is). – Dennis Williamson Nov 8 '10 at 3:54
@Dennis: Thanks for the correction. I hadn't thought of using getconf here. It sounds nice in principle, but it's hard to ensure that the results apply to the particular C compiler you'll be using, if there's more than one (typically gcc/icc or similar on Linux, gcc/native cc elsewhere). On a standard system getconf should apply to c89 or c99 in $(getconf PATH), but in practice I'd worry about someone installing an alternate cc which is ran by the vendor c89 wrapper. – Gilles Nov 8 '10 at 22:22
There is a . missing in the regex: grep '^flags.*:.*\blm\b' /proc/cpuinfo. Also it only works for me without the -q flag – byf-ferdy Apr 27 '14 at 19:59
@byf-ferdy It wasn't a missing .: I had “zero or more spaces”, but actually there's a tab. I've changed the regexp to allow tabs as well. With the -q flag, there's no output, but the exit status of the command tells you whether the flag is present. If you want output, remove the -q flag. – Gilles Apr 27 '14 at 20:04
@Gilles ah I didn't know about the -q flag. Ty, works now :) – byf-ferdy Apr 27 '14 at 20:13

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.

share|improve this answer
Anything else and you're running 32-bit, or non-PC hardware (such as alpha, sparc64, ppc64, ... – Gilles Nov 8 '10 at 0:08
@Gilles: Thanks, I edited my answer accordingly. – Wuffers Nov 8 '10 at 0:11


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

share|improve this answer
That's not the question. – harrymc Nov 10 '10 at 19:17
uname -m | sed 's/x86_//;s/i[3-6]86/32/'
share|improve this answer

getconf uses the fewest system calls:

$ strace getconf LONG_BIT | wc -l

$ strace arch | wc -l

$ strace uname -m | wc -l

$ strace grep -q lm /proc/cpuinfo | wc -l
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .