I need in a bash script to detect the architecture of the current Linux. I see sometimes uname is giving the info but is tricky. It depends of the system to show it in one place or another or even not be shown on uname command.

On debian based i saw the dpkg --print-architecture command, but is working only for Debian based.

I need to check if is i386, amd64, armhf, armel, arm64 or whatever.

Is there a nice "universal" stuff working on all Linux systems? I need currently installed kernel architecture... not what my hardware is capable of

  • 1
    Do you want the CPU’s architecture, the kernel’s architecture, or the runtime architecture? Apr 25, 2020 at 21:29
  • Consider the following case. I own a phone which supports both arm64 and armhf. I've installed arm64 kernel which is stock. Then i have a chroot inside my android which is armhf. So when i run uname -m, it gives me aarch64 and if i try to install a package depending on that, it will fail as the chroot is armhf. dpkg --print-architechture is what he is looking for as he may come to the same situation I'm facing with my phone. He is asking for an alternative to this command that can be used across all Linux flavours. Apr 25, 2020 at 22:19
  • I want the installed kernel arch. Commands like uname -m are showing what my hardware is capable of... but is not showing what i have installed, so is not valid for me. I edited my question Apr 26, 2020 at 12:33

2 Answers 2


GNU coreutils come with the arch and uname -m commands which print the architecture your kernel is compiled for.

dpkg --print-architecture is the right tool if you want to find out for which architectures binaries can be installed on the system (Application Binary Interface, ABI). Note that on so called multi-arch systems that's more than one architecture. Example: A Debian PC might be running a 64 bit kernel on a 64 bit CPU and mixed 32/64 bit software. This can be useful if you want to leverage the advantages of 64 bit while being able to execute a 32 bit legacy application. Debian and derived distributions are very strong in this area, not sure if other distros offer something similar.

In case you're looking for a portable way for finding out the architecture (as in ABI) used inside a chroot environment or a container you could check the architecture one of your system files was compiled for, like

$ file -Lb /usr/bin/ld | cut -d, -f2

There are many possibilities; uname -m is one, /proc/cpuinfo is another. getconf also has lots of configuration info that could probably be parsed. Maybe see if there's something in the LSB (Linux Standard Base)?

You must log in to answer this question.

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