arch Command in Linux



You can use the arch command in Linux to check your computer architecture. When you run the arch command without any option or argument, it prints the architecture identifiers, such as x86_64 or i386, and others. It is a handy command line tool that is used to quickly check your system’s architecture. System administrators often use this command in the script or configuration files to adapt settings based on the system’s architecture.

Table of Contents

How to Install arch Command in Linux?

By default, the arch command-line utility is preinstalled on your Linux system, and you can confirm the installation by running the below-given command −

arch --version
arch Command Linux 1

The arch command comes under the GNU coreutils package that is preinstalled on your Linux system and cannot be deleted easily. However, if you have done that accidentally, you can reinstall the coreutils package directly from the Linux repository.

If you are using Debian based systems like Ubuntu, Debian and other such systems, use the apt package manager to install coreutils package from the following command −

sudo apt install coreutils 

The Red Hat and Fedora users can use the yum package manager to install coreutils package on their systems from the following command −

sudo yum install coreutils

For Arch users, they can install coreutils package on their system from the below-provided command −

sudo pacman -S coreutils

Syntax for arch Command in Linux

The syntax for the arch command on Linux is pretty straightforward, which is provided below −

arch [options]

Here, the arch keyword will invoke the arch command, while the options can be replaced with flags or options to change the arch command behavior.

Different Options Available for arch Command

The arch command doesn’t have any options or flags apart from the version or help options. If you use the arch command with the --version flag, it will display the arch command version installed on your Linux system −

arch --version
arch Command Linux 2

If you use the arch command with the --help flag, it will display the help section of the command on the terminal.

arch --help
arch Command Linux 3

Examples of arch Command in Linux

As previously mentioned, you can use the arch command to find your system architecture. Here, in this section, we will provide you with two examples −

  • Use arch Command Directly
  • Use arch Command in a Script

Let’s explore them.

Using arch Command Directly

If you use the arch command directly on your Linux terminal without an argument, it will display your system architecture −

arch
arch Command Linux 4

Using arch Command in a Script

Let’s provide another example where instead of using the arch command in the terminal directly, we are using it in the script. For that purpose, first create a script file with your desired name using the nano editor on Linux system −

sudo nano script.sh

Inside the script, add the following line −

#!/bin/bash
# This script displays the architecture of the system

architecture=$(arch)
echo "The machine architecture is: $architecture"
arch Command Linux 5

Once the lines are added, save your script file using CTRL+X, add Y and press the Enter button.

After creating the script file, it’s time to run it. You can use bash or sh command to run the script file on your Linux system −

bash script.sh
arch Command Linux 6

Note − You can also run the script with ./script.sh, however, this can only be done once you make the script executable on your Linux system from the following command −

sudo chmod +x script.sh

That’s how you can use the arch command to check your system architecture in Linux.

Alternative Command for arch in Linux

Besides using the arch command, you can also use the uname command with -m flag to check your system architecture −

uname -m
arch Command Linux 7

Conclusion

The arch is a useful command that allows you to check your system architecture on Linux. This command only includes options like --version and --help to check the command's version and open help section, respectively. The syntax for arch command is simple, and the examples provided in this guide will help you directly run the arch command or run it inside a script file. Apart from that, the alternative command uname -m can also be used in case arch command is not working on your Linux system.

Advertisements