23

what would be a command to run in different distros?

10 Answers 10

37

"uname -m" is the command you're looking for. You can run both 32bit and 64bit on modern intel and AMD processors, so "uname -p" is not going to help you (in addition it mostly doesn't work these days, this here core2 thinks the response to "uname -p" is "unknown").

Looking for existence of /usr/lib64 (as has been suggested) is not going to help you either, since some hardware and system related packages will install both 32bit and 64bit libraries to be on the safe side. On my (debian) system the fakeroot package does just that.

As for the output of "uname -m", if it's i386 or i686 it's 32bit, if it's x86_64 (or alpha, or ia64 or some other 64bit architecture I've never seen :) it's 64bit.

(as a fun aside, my 64bit FreeBSD server returns "amd64", which might be a bit strange for an intel quadcore but totally understandable if you know the history of the x86 64bit architecture)

  • 1
    does this tell you the installation architecture or the actual CPU architecture. For example, if you installed 32-bit OS on 64bit cpu, would this return i686 or x86_64? – monkut Jul 19 '11 at 8:56
15

uname -a and look for x86_64. If you want to know if your CPU can handle 64bit, cat /proc/cpuinfo and look for lm within the flags.

  • 3
    cat /proc/cpuinfo | grep ^flags | perl -e'$_=<>;print "x86_64\n":"not x86_64\n"' – Brad Gilbert Jun 17 '09 at 21:39
6

for RedHat/CentOS:

$ uname -a
Linux cs-centos 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 12:03:43 EST 2008 i686 athlon i386 GNU/Linux

32-bit

  • i686 and/or i386

64-bit

  • would have x86_64 in uname -a output
6

Just to confuse things, you can run a 64bit kernel with a 32bit userland, which is what I'm doing. In this case, uname -m returns x86_64 but I don't have any 64bit libraries installed so most 64bit programs won't run.

So once you check uname, you need to look for /lib64/ld-linux-x86-64.so.2, /lib64/libc-2.7.so and /lib/ld-linux.so.2, /lib/libc-2.7.so to see whether 64bit and 32bit libraries are available. And to really make sure, run those files and see if they execute correctly.

Another useful piece of information is the output of lsb_release -a which is cross-distro and will report what architecture-specific LSB modules are available.

  • 2
    Unfortunately lsb_release -a doesn't output the userland architecture – Joni Feb 22 '13 at 10:50
6

$> getconf LONG_BIT Answer: 32 or 64.

2

Another way to do it is to ask perl what compiler said the size of a long integer is:

$ perl -MConfig -e 'print $Config{longsize}*8 . "\n";'
64

vs.

$ perl -MConfig -e 'print $Config{longsize}*8 . "\n";'
32

Or, if you've got gcc installed, the same in C:

$ cat > bits.c <<EOC
> #include <stdlib.h>
> #include <stdio.h>
> 
> int main(void) {
>    printf("%d\n", (int)sizeof(long)*8);
> 
>    exit(0);
> }
> EOC
$ gcc -Wall -o bits bits.c
$ ./bits
64

vs.

[...]
> EOC
$ gcc -Wall -o bits bits.c
$ ./bits
32

:-)

  • That just tells you what the default version of perl does .. – pjc50 Oct 27 '09 at 12:25
  • @pjc50: And your point is? – asjo Nov 23 '09 at 23:21
  • 1
    his point is that you could have a 32 bit Perl on a 64 bits system – niXar Apr 16 '10 at 9:49
  • @niXar: I guess that is possible, but having that would make for quite the... odd Linux distribution. Anyway, use the C version then ;-) – asjo May 4 '10 at 19:15
1

As a duplicate of :

Linux + how to verify linux version 32 Bit or 64 Bit

uname -m will only give you the running 'arch'/architecture of the kernel. It will NOT tell you if your are running a 32 bits GNU/Linux distribution on a 64bits capable CPU.

To know your CPU capability:

 cat /proc/cpuinfo

The 'LM' flag should be present in 64bits systems as it represent 'LONG MODE' (64bit Extensions, AMD’s AMD64 or Intel’s EM64T).

0
$ uname -p

x86_64
  • 2
    "uname -p" returns "athlon" on my system - not too helpful... – webwesen Jun 17 '09 at 20:18
  • 3
    I've run into machines where I get "unknown" from uname -p as well.. – Cube_Zombie Jun 17 '09 at 20:36
0

If you have /usr/lib64 you're running x86_64..

  • 3
    mkdir /usr/lib128 && echo "Look ma', I have a 128 bit computer!" – niXar Apr 16 '10 at 9:50
0

Brad Gilbert's command had a perl bug. I've fixed it and the below command works: cat /proc/cpuinfo | grep ^flags | perl -e '$=<>;print ($?"x86_64\n":"not x86_64\n")'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.