Justin
Justin

Reputation: 45350

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: 125

Views: 137331

Answers (7)

WounderWaffle
WounderWaffle

Reputation: 23

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: 2705

$ arch

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

Upvotes: 8

Zstack
Zstack

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

Roman Panaget
Roman Panaget

Reputation: 2428

I suggest using:

dpkg --print-architecture

Upvotes: 161

Justin
Justin

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

ephemient
ephemient

Reputation: 204718

uname -m

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

Upvotes: 95

Related Questions