Justin
Justin

Reputation: 45410

How to detect 386, amd64, arm, or arm64 OS architecture via shell/bash

I'm looking for a POSIX shell/bash command to determine if the OS architecture is 386, amd64, arm, or arm64?

Upvotes: 126

Views: 140700

Answers (7)

WounderWaffle
WounderWaffle

Reputation: 25

For Windows, use:

echo %PROCESSOR_ARCHITECTURE%

Upvotes: 0

Akshay Kakade
Akshay Kakade

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

Ilia Sidorenko
Ilia Sidorenko

Reputation: 2725

$ arch

Also works. Tested on Debian-based and RPM-based distros.

Upvotes: 8

Zstack
Zstack

Reputation: 4753

$ lscpu | grep Architecture

Architecture:                    x86_64

Or if you want to get only the value:

 $ lscpu | awk '/Architecture:/{print $2}'

x86_64

Upvotes: 8

Roman Panaget
Roman Panaget

Reputation: 2448

I suggest using:

dpkg --print-architecture

Upvotes: 163

Justin
Justin

Reputation: 45410

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

ephemient
ephemient

Reputation: 205014

uname -m

prints values such as x86_64, i686, arm, or aarch64.

Upvotes: 96

Related Questions