Linux, Ubuntu: how to tell if 32 or 64 bit installed

A question I get regularly from other sysadmins – how to tell if you’re running a 32 or 64 bit install (vs CPU) of Linux?

Here’s one way – use the file command on /sbin/init:

# on a 32 bit install
% file /sbin/init
/sbin/init: ELF 32-bit LSB executable....

# on a 64 bit install
% file /sbin/init
/sbin/init: ELF 64-bit LSB shared object, x86-64...


I got a few comments on this (thank you) saying that I was wrong or “haven’t you heard of uname?”…

1. CPU vs Kernel

One comment said I was wrong and should use grep against the cpu info:

$ grep ^flags /proc/cpuinfo | grep lm

Unfortunately the commenter hadn’t read my post correctly – I’m interested in whether the operating system is 32/64 bit, not the cpu.

2. Use uname

Other comments said I should use uname with particular flags (as if I’d never heard of uname before….). Unfortunately the manpage for uname is a good example of manpage considered harmful. Let’s have a look at what it says for the various options:

% man uname
-m, --machine
    print the machine hardware name

-p, --processor
    print the processor type or "unknown"

-i, --hardware-platform
    print the hardware platform or "unknown"

What is the difference between the “machine hardware name”, the “processor type”, and the “hardware platform”? Googling doesn’t turn up a good explanation. I could look at the source code for uname, or run uname on a machine I which already has known hardware and interpret the results, then work out the flags to use on the target machine. Or I could just rote-memorise uname -m and not know what it means.

Bzzt, fail. I know what the file command does, I use it regularly for cross-compiling stuff.

file /sbin/init is what I use.


Share This


10 Responses to Linux, Ubuntu: how to tell if 32 or 64 bit installed

  1. Wouldn’t it just be easier to use uname -m

    [22:01:55] @sarah ~ 2007 $ uname -m

  2. This is wrong!
    Cause you can install a 32bit distro to a 64bit machine.

    This is how to find if your cpu processor has long mode (64bit) capabilities

    $ grep ^flags /proc/cpuinfo | grep lm

  3. just use good old uname:

    $ uname -a
    Linux host 2.6.32-279.5.1.el6.x86_64 #1 SMP Tue Aug 14 16:11:42 CDT 2012 x86_64 x86_64 x86_64 GNU/Linux

    $ uname -a
    Linux host 2.6.32-5-686 #1 SMP Sun May 6 04:01:19 UTC 2012 i686 GNU/Linux

    uname has also available in unix for ages, know your tools

  4. Matt Hannigan

    I like the simplicity of your approach very much!

    One wrinkle is that init can be a symlink (to e.g. systemd), so you need to dereference it. You’d only care about this if you’re writing a script to be used forever and everywhere.

    $ file /sbin/init
    /sbin/init: symbolic link to `../bin/systemd'
    $ file -L /sbin/init
    /sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped

  5. Could I suggest the “arch” command, from the coreutils package? It does the same as “uname -m”, but is easier to remember. Works on Ubuntu 12.04, Debian 6, and Fedora 17.

    Also if you really prefer the file command, it might be better to use “file -L /sbin/init”, because at least on Fedora, it’s a symbolic link. ^H^H^H Whoops, just saw Matt had suggested that, so pls disregard.

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>