-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux which Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to which on Linux, covering Arch Linux, CachyOS, and other distributions including finding command locations, executable paths, and command resolution.
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
Basic usage:
# Find command
which ls
# Output: /usr/bin/lsFind several:
# Find multiple
which ls cat grep
# Path for eachShow all:
# Show all matches
which -a python
# Shows all python executables in PATHCheck existence:
# Check if exists (script)
if which command > /dev/null 2>&1; then
echo "Command exists"
fiVerify PATH:
# Check PATH
echo $PATH
# Then find command
which commandUse in scripts:
#!/bin/bash
CMD=$(which mycommand)
if [ -n "$CMD" ]; then
echo "Found: $CMD"
else
echo "Not found"
fiCheck PATH:
# Verify command exists
which command
# Check if in PATH
echo $PATH | grep -o '[^:]*'
# Or use whereis
whereis commandThis guide covered which usage, command location, and path resolution for Arch Linux, CachyOS, and other distributions.
- whereis Guide - Find commands and files
- locate Guide - Find files by name
- find Guide - Advanced file searching
-
which Documentation:
man which
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.