Skip to Content
gnux

archx

Print machine architecture.

Mirrors GNU arch. Run it as archx, or as gnux archx.

Synopsis

archx [OPTION]...

GNU reference

Description

archx prints the machine hardware name, exactly as unamex -m does, and takes no operands. The name comes from the operating system: x86_64 or aarch64 on Linux, x86_64 or arm64 on macOS, amd64 or arm64 on FreeBSD. On Windows, and in the browser playground, gnux names the architecture it was built for the way Linux does (x86_64, aarch64, wasm32).

Permissions

Needs no permissions. Reads only system information.

Use cases

  • Picking the right binary to download in an install script.
  • Recording the machine's architecture in a CI log or a bug report.
  • Skipping a step that only works on one architecture.
  • Naming build output after the architecture it was built on.
  • Checking whether a shell runs under emulation (Rosetta, QEMU).

Flags

      --help      display this help and exit
      --version   output version information and exit

Examples

archx
Output
x86_64
unamex -m

Pick a download for this machine

curl -LO "https://example.com/tool-$(archx).tar.gz"

Run a step only on 64-bit ARM

case "$(archx)" in aarch64|arm64) echox 'ARM build' ;; esac

Name an output directory after the architecture

mkdirx -p "build/$(archx)"

Record the system in a log

echox "$(unamex -s) $(archx)" >> build.log

Save the architecture in a variable

arch=$(archx)
echox "$(archx), $(nprocx) cores"

Compare with the expected architecture

[ "$(archx)" = x86_64 ] || echox 'not x86_64'

Branch on the architecture in the portable gnux shell

gnux shell -c 'case $(archx) in x86_64) echox intel ;; *) echox other ;; esac'

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

archx --help                # options, first examples, exit status
gnux help archx             # this page: the full manual
gnux help archx --OPTION    # one option in depth, with its examples

See also

On this page