Reputation: 45350
I'm looking for a POSIX shell/bash command to determine if the OS architecture is 386
, amd64
, arm
, or arm64
?
Upvotes: 125
Views: 137331
Reputation: 167
uname -m
This will display the machine hardware name, which will indicate the processor architecture.
If the output is "arm", it means the processor architecture is ARM-based. If the output is "x86_64", it means the processor architecture is AMD-based (also known as x86-64 or Intel 64).
Upvotes: 11
Reputation: 2705
$ arch
Also works. Tested on Debian-based and RPM-based distros.
Upvotes: 8
Reputation: 4743
$ lscpu | grep Architecture
Architecture: x86_64
Or if you want to get only the value:
$ lscpu | awk '/Architecture:/{print $2}'
x86_64
Upvotes: 8
Reputation: 45350
I went with the following:
architecture=""
case $(uname -m) in
i386) architecture="386" ;;
i686) architecture="386" ;;
x86_64) architecture="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="arm" ;;
esac
Upvotes: 42
Reputation: 204718
uname -m
prints values such as x86_64
, i686
, arm
, or aarch64
.
Upvotes: 95