Skip to content

Linux which Guide

Mattscreative edited this page Nov 20, 2025 · 2 revisions

🔍 Linux which Guide

Complete beginner-friendly guide to which on Linux, covering Arch Linux, CachyOS, and other distributions including finding command locations, executable paths, and command resolution.


📋 Table of Contents

  1. Understanding which
  2. which Basics
  3. Finding Commands
  4. Path Resolution
  5. Troubleshooting

🎯 Understanding which

What is which?

which locates commands in PATH.

Uses:

  • Find commands: Locate executable files
  • Check availability: See if command exists
  • Path resolution: Find command path
  • Debugging: Troubleshoot command issues

Why it matters:

  • Command location: Find where commands are
  • Path debugging: Debug PATH issues
  • Scripts: Verify command availability

🔍 which Basics

Find Command

Basic usage:

# Find command
which ls

# Output: /usr/bin/ls

Multiple Commands

Find several:

# Find multiple
which ls cat grep

# Path for each

🔎 Finding Commands

All Matches

Show all:

# Show all matches
which -a python

# Shows all python executables in PATH

Silent Mode

Check existence:

# Check if exists (script)
if which command > /dev/null 2>&1; then
    echo "Command exists"
fi

🛤️ Path Resolution

PATH Check

Verify PATH:

# Check PATH
echo $PATH

# Then find command
which command

In Scripts

Use in scripts:

#!/bin/bash
CMD=$(which mycommand)
if [ -n "$CMD" ]; then
    echo "Found: $CMD"
else
    echo "Not found"
fi

🔧 Troubleshooting

Command Not Found

Check PATH:

# Verify command exists
which command

# Check if in PATH
echo $PATH | grep -o '[^:]*'

# Or use whereis
whereis command

📝 Summary

This guide covered which usage, command location, and path resolution for Arch Linux, CachyOS, and other distributions.


🔗 Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally