73

I'm writing a shell script, and I need to know the architecture, i.e. PPC or Intel. Back in the day, there was a program /bin/arch that told you, but my Mac doesn't seem to have it.

Is there an easy way I can do this? grep for something in a log file? Call some other program that spits that out as a side effect?

It would be nice to know what OS version I'm running too, but that may not be necessary.

1

5 Answers 5

83

There are many ways, but try uname -a.

4
  • 27
    uname -p gives just the processor architecture. man uname for other options. Jun 3, 2010 at 16:55
  • 9
    @DougHarris I get x86_64 with -a but i386 with -p
    – GP89
    Jan 29, 2015 at 14:45
  • @GP89 Have the same condition with you.
    – 廖茂生
    Sep 28, 2020 at 7:53
  • @GP89 i386 is the machine processor architecture, while x86_64 is current hardware platform - from the man page. May 14, 2023 at 20:55
27

uname -m seems to output the same information as /bin/arch.

4
  • 11
    Not with me. arch outputs i368 and uname -m outputs x84_86. I run OSX on a 64bit machine.
    – user52375
    Dec 18, 2012 at 19:35
  • 1
    @ErikAigner: Typo, perhaps? Shouldn't it be x86_64? Dec 19, 2012 at 6:02
  • Of course arch should return x86_64, that's why it's so strange. But I don't know why.
    – user52375
    Dec 19, 2012 at 7:31
  • 1
    Same here: $ uname -m x86_64 $ arch i386
    – Davi Lima
    Jan 21, 2015 at 11:31
22

arch is available in /usr/bin/arch

You can get OS version information with sw_vers

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.6.3
BuildVersion:   10D573
$ sw_vers -productVersion
10.6.3
8

You can use sysctl to get information about your CPU:

$ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Apple M1 Pro

Now you can take this string and search in the internet to get details about this CPU brand.

If you want more information about the CPU you can use this command:

$ sysctl machdep.cpu
machdep.cpu.cores_per_package: 10
machdep.cpu.core_count: 10
machdep.cpu.logical_per_package: 10
machdep.cpu.thread_count: 10
machdep.cpu.brand_string: Apple M1 Pro
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTSE64 MON DSCPL VMX EST TM2 SSSE3 CX16 TPR PDCM SSE4.1 SSE4.2 AES SEGLIM64
machdep.cpu.feature_bits: 151121000215084031
machdep.cpu.family: 6
1
  • 2
    Running any kind of EDR which might run on the client under rosetta makes this the only valid answer since this checks the underlaying machine itself and not the current prompt which might be wrong due to rosetta.
    – hrdy
    Jul 10, 2023 at 10:45
5

Another method nobody mentioned is:

$ machine
arm64e
MACHINE(1)                                                               General Commands Manual                                                               MACHINE(1)

NAME
     machine – print machine type

SYNOPSIS
     machine

DESCRIPTION
     The machine command displays the machine type.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .