When using the native shell say /bin/bash -i
or /bin/zsh -i
, Klas Mellbourn's answer works as expected.
If using a shell that was installed via an Intel/Rosetta Homebrew installation, then uname -p
returns i386
, and uname -m
returns x86_64
, as indicated by Datasun's comment.
To get something that works across environments (Apple Silicon Native, Rosetta Shell, Linux, Raspberry Pi 4s), I use the following from the dorothy dotfile ecosystem:
is-mac && test "$(get-arch)" = 'a64'
If you aren't using dorothy, the relevant code from dorothy is:
https://github.com/bevry/dorothy/blob/1c747c0fa6bb3e6c18cdc9bae17ab66c0603d788/commands/is-mac
test "$(uname -s)" = "Darwin"
https://github.com/bevry/dorothy/blob/1c747c0fa6bb3e6c18cdc9bae17ab66c0603d788/commands/get-arch
arch="$(uname -m)" # -i is only linux, -m is linux and apple
if [[ "$arch" = x86_64* ]]; then
if [[ "$(uname -a)" = *ARM64* ]]; then
echo 'a64'
else
echo 'x64'
fi
elif [[ "$arch" = i*86 ]]; then
echo 'x32'
elif [[ "$arch" = arm* ]]; then
echo 'a32'
elif test "$arch" = aarch64; then
echo 'a64'
else
exit 1
fi
Jatin Mehrotra's answer on a duplicate question gives details on how to get the specific CPU instead of the architecture. Using sysctl -n machdep.cpu.brand_string
outputs Apple M1
on my M1 Mac Mini, however outputs the following on a Raspberry Pi 4 Ubuntu Server:
> sysctl -n machdep.cpu.brand_string
Command 'sysctl' is available in the following places
* /sbin/sysctl
* /usr/sbin/sysctl
The command could not be located because '/sbin:/usr/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with your user account.
sysctl: command not found
> sudo sysctl -n machdep.cpu.brand_string
sysctl: cannot stat /proc/sys/machdep/cpu/brand_string: No such file or directory
uname -p
will probably give you the information you want, but I don't have an M1 to test. – Illuminati