I'm trying to write a script which will determine actions based on the architecture of the machine. I already use uname -m to gather the architecture line, however I do not know how many ARM architectures there are, nor do I know whether one is armhf, armel, or arm64.

As this is required for this script to determine whether portions of the script can be run or not, I am trying to find a simple way to determine if the architecture is armhf, armel or arm64. Is there any one-liner or simple command that can be used to output either armhf, armel, or arm64?

The script is specifically written for Debian and Ubuntu systems, and I am tagging as such with this in mind (it quits automatically if you aren't on one of those distros, but this could be applied in a much wider way as well if the command(s) exist)


EDIT: Recently learned that armel is dead, and arm64 software builders (PPA or virtual based) aren't the most stable. So I have a wildcard search finding arm* and assuming armhf, but it's still necessary to figure out a one liner that returns one of the three - whether it's a Ubuntu/Debian command or a kernel call or something.

  • case $(arch) in ; armf)... ;; armel)... ;; arm64)... ;; *) exit ;; esac do you meen something like this? – Costas Jan 23 '15 at 21:26
  • @Costas Yes, that's effectively what i'm after, but getting the arch is the tricky part. Since solutions might be distribution and OS-model specific, Debian and Ubuntu are similar and are my target, so solutions that would get the arch out and then usable would be great. (This isn't a pure-programming question either, I just need the command to grab the specific arch - i already have i386, i686, and x86_64 cases based on uname -m, but nothing for arm??... or at least, nothing that identifies armhf, armel, or arm64). – Thomas Ward Jan 23 '15 at 22:07
  • What do you mean? – Costas Jan 23 '15 at 22:13
  • @Costas On ARM setups, uname -m spits out the specific arm board - armv7l for example. It doesn't explicitly say whether it's armel, armhf, or arm64 - which is what I need $(arch) to end up as in order to weed out incompatible OS architectures with. – Thomas Ward Jan 23 '15 at 22:17
  • You might be better off parsing /proc/config.gz if it is there. – umeboshi Jan 26 '15 at 16:41
up vote 22 down vote accepted
dpkg --print-architecture

will output the primary architecture of the machine it's run on. This will be armhf on a machine running 32-bit ARM Debian or Ubuntu (or a derivative), arm64 on a machine running 64-bit ARM.

Note that the running architecture may be different from the hardware architecture or even the kernel architecture. It's possible to run i386 Debian on a 64-bit Intel or AMD CPU, and I believe it's possible to run armhf on a 64-bit ARM CPU. It's even possible to have mostly i386 binaries (so the primary architecture is i386) on an amd64 kernel...

  • Right but this will determine the architecture needed for the script's packages. I will test this today, thanks. – Thomas Ward Jan 28 '15 at 13:08
  • On a android device, there is no dpkg command. What should I do to detect architecture of a android device? – Dr.jacky Jan 13 '16 at 9:22
  • @Mr.Hyde this question specifically targeted Debian and Ubuntu; I suggest you ask a new question if you want the answer for Android, either here or on android.stackexchange.com. – Stephen Kitt Jan 13 '16 at 9:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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