Linuxips
  • Home
  • Linux
  • Debian
  • Ubuntu
  • Fedora
  • Arch Linux
No Result
View All Result
Linuxips
  • Home
  • Linux
  • Debian
  • Ubuntu
  • Fedora
  • Arch Linux
No Result
View All Result
Linuxips
No Result
View All Result
Home Commands

How to Use the which Command in Linux

admin by admin
January 2, 2026
Reading Time: 3 mins read
0
How to Use the which Command in Linux

In this tutorial, you will learn to use the which command. The which command allows users to search the list of paths in the $PATH environment variable and outputs the full path of the command specified as an argument. The command works by locating the executable file matching the given command.

Contents hide
1 Prerequisites
2 Linux which Command Syntax
2.1 Arguments
2.2 Options
2.3 For example:
2.4 Exit Status
3 Linux which Command Examples
3.1 1. Display the Path of Any Executable File
3.2 2. Display Multiple Paths of Executable Files
3.3 3. Exclude Shell Built-ins
4 Conclusion
4.1 Related Linux Tutorials:

Prerequisites

  • A system running Linux
  • Access to the terminal (Ctrl + Alt + T)

Linux which Command Syntax

The syntax for the which command is:

$ which -a [argument]

Arguments

The [argument] variable specifies the command or commands you want to find.

For example, the following command outputs the location of the cat command:

$ which cat

Options

The which command has only one option, -a. It is optional and used to print all the matches it finds.

The command searches for matches from left to right. If there are multiple matches found in the directories listed in $PATH, which prints only the first one. The -a option instructs which to print all the matches.

For example:

$ which -a touch
Note: Unlike many other commands, which has no –help option. To see the command description and help, run man which.

Exit Status

The which command returns one of the following values that indicate its exit status:

  • 0. All arguments were found and executable.
  • 1. One or more arguments don’t exist or aren’t executable.
  • 2. An invalid option has been specified.

Linux which Command Examples

The following examples showcase how the which command works and how to use the available option.

1. Display the Path of Any Executable File

To display the path of any command, pass the command name as an argument after which.

For example:

$ which tr

Find the tr command executable with which. The output shows the path to the tr command executable file, located in /usr/bin/tr.

2. Display Multiple Paths of Executable Files

which accepts multiple arguments and outputs the path to each one in the specified order.

For example:

$ which nc mount sort

Find the paths to multiple commands using which. The command works through the supplied list and outputs the results for the nc command, mount command, and sort command, separating each result with a newline character.

3. Exclude Shell Built-ins

As previously mentioned, the which command excludes shell built-ins from its output.

For example, asking for the location of the read and man commands only outputs the location for the man command executable file, as read is a bash shell command.

$ which read man

 

Conclusion

This tutorial showed how to use the which command in Linux to find the path to a command’s executable binary. See and download our Linux commands cheat sheet for other essential Linux commands and examples of using them.

Related Linux Tutorials:

  • How to Install Cisco Packet Tracer on Ubuntu.
  • How to install Tweak Tool on Ubuntu 21.04.
  • ZSH to BASH | How to Install ZSH on Ubuntu.
  • How to Install Ubuntu.
  • How to Install PuTTY on Ubuntu
ShareTweetSendShareShare
Previous Post

How to Work with Nano Editor on Linux

admin

admin

Linuxips is a Linux blog that publishes articles and tutorials about server operations, installations, new techniques and Linux security.

Related Posts

How to Work with Nano Editor on Linux
Linux

How to Work with Nano Editor on Linux

January 1, 2026
How to Install HTOP on Ubuntu
Commands

How to Install HTOP on Ubuntu 22.04 (Monitor System Processes)

December 30, 2025
How to Install Vim on Arch Linux
Arch Linux

How to Install Vim on Arch Linux : A Quick Guide

December 29, 2025
Install ZSH on Arch Linux
Arch Linux

How to Install ZSH on Arch Linux

January 6, 2024
How To Use AppImage in Linux
Linux

How To Use AppImage in Linux [Complete Guide]

April 2, 2023
How To Install uGet Download Manager On Ubuntu
Linux

How To Install uGet Download Manager On Ubuntu

March 8, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

You might also like

How to Use the which Command in Linux

How to Use the which Command in Linux

January 2, 2026
How to Work with Nano Editor on Linux

How to Work with Nano Editor on Linux

January 1, 2026
How to Locate and kill a Process on Ubuntu 22.04

How to Locate and kill a Process on Ubuntu 22.04

December 31, 2025
How to Install HTOP on Ubuntu

How to Install HTOP on Ubuntu 22.04 (Monitor System Processes)

December 30, 2025
How to Install Vim on Arch Linux

How to Install Vim on Arch Linux : A Quick Guide

December 29, 2025
Tails 7.2

Tails 7.2 Released with Tor Browser 15.0 and Linux Kernel 6.12 LTS

November 13, 2025

© 2024 Linuxips.com - Linux Tips, Tricks and Tutorials.

  • Home
  • Web Stories
  • Privacy Policy
  • Contact Us
  • Disclaimer
No Result
View All Result
  • Home
  • Linux
  • Debian
  • Ubuntu
  • Fedora
  • Arch Linux

© 2024 Linuxips.com - Linux Tips, Tricks and Tutorials.