Linux Terminal Command: which

The which command is an essential tool in Foundations & Navigation. In this tutorial, we will explore what which does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The which command checks your shell $PATH directories and prints the absolute path of the executable that would run if you typed the command.


Common Options & Syntax

which [options] [arguments]

Here are the most common flags used with which:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
which python3

What it does: Prints the path of the ‘python3’ executable (e.g. /usr/bin/python3).


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
which -a git

What it does: Lists all instances of ‘git’ found in the directories listed in the path variable, not just the first one.


⚙️ Warning & Common Pitfalls

[!WARNING] which does not identify shell builtins (like cd or alias) or custom functions. Use the bash builtin type or command -v instead.


Here are some related posts on cli_tty1 you might want to check out: