Read the Kernel Machine Architecture with arch

A deploy script that picks the wrong binary for the host usually skipped a one-word check that arch exists to answer. It prints the machine architecture reported by the running Linux system; you will capture that in a script and confirm which GNU coreutils implementation is installed. On this machine, arch is GNU coreutils 9.4 from package version 9.4-3ubuntu6.3. Allow about five minutes. You need a shell and a normal user account; none of the commands in this guide needs sudo.

1. Check the installed command

The local manual describes arch as a command that prints the machine architecture. The installed manual page is dated August 2026 and identifies GNU coreutils 9.4. Confirm the executable and package before relying on examples in a script:

$ command -v arch
/usr/bin/arch
$ arch --version
arch (GNU coreutils) 9.4
$ dpkg-query -W -f='${Package} ${Version}\n' coreutils
coreutils 9.4-3ubuntu6.3

The package query is specific to Debian and Ubuntu systems. The command itself is not: on another distribution, use that distribution's package tool if you need to identify the owning package. The useful checkpoint is that command -v resolves the program you intend to run.

2. Print the architecture once

Run arch with no options:

$ arch
x86_64

Your output may be different. Treat it as data supplied by this host, not as text to copy from this example. The command writes the machine name followed by a newline and exits without changing files, services or system configuration.

For a second read-only check, compare it with the machine field from uname:

$ test "$(arch)" = "$(uname -m)" && echo 'architecture fields match'
architecture fields match

The manual explicitly documents arch as the same result as uname -m. This comparison is a useful diagnostic if a script appears to be receiving unexpected output. It does not identify every CPU feature or list all architectures that a compiler might support.

3. Use the value in a shell script

Capture the result with command substitution when a later decision depends on the host architecture:

$ machine_arch=$(arch)
$ printf 'machine architecture: %s\n' "$machine_arch"
machine architecture: x86_64

Quote the variable when you print or pass it on. Although the normal output is a short name without spaces, quoting makes the shell boundary explicit and avoids a habit that becomes risky when the value comes from somewhere else.

A simple allow-list check can stop a script before it selects an incompatible binary:

$ case "$(arch)" in
>   x86_64|aarch64) echo 'supported machine architecture' ;;
>   *) printf 'unsupported architecture: %s\n' "$(arch)" >&2; exit 1 ;;
> esac
supported machine architecture

Replace the names in the case statement with the values your software actually supports. Do not assume that every system uses x86_64; an ARM machine commonly reports aarch64, but the host result is authoritative for the host on which the script is running.

4. Keep architecture checks in the right place

arch reports the machine name. It does not install a package, choose a repository, inspect an executable, or translate one architecture name into another distribution's package naming scheme. Do not use its output as a package-manager argument without checking that the package manager accepts the same vocabulary.

It is also separate from an executable compatibility check. If you are investigating a downloaded program, inspect the file with a tool such as file before running it, and obtain it from a source you trust. An architecture match does not make an untrusted binary safe, nor does it prove that its libraries or ABI requirements are present.

Keep the command in an ordinary, non-privileged discovery step. Reading the architecture cannot repair a failed installation. If a deployment needs a different package or binary, stop the deployment and follow its documented recovery procedure rather than trying random architecture aliases.

5. Use the built-in diagnostics

The installed command has two documented options. --help prints its short usage text and exits:

$ arch --help
Usage: arch [OPTION]...
Print machine architecture.

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

Use --version when a bug report or deployment record needs the implementation version. Keep the output with the operating system details, because the same command name can be supplied by a different package on another host.

If arch is not found, check the command search path without changing it:

$ printf '%s\n' "$PATH"
$ type -a arch

If the command exists at /usr/bin/arch but a script cannot find it, the script has a different PATH. Use the intended absolute path only after confirming it with command -v, or fix the script's environment according to its service or scheduler documentation. Do not copy an executable into a system directory as a quick fix.

Done means