Cat the Source of Program in Path

May 27, 2026

When you need to inspect a shell script that's somewhere in your PATH, you don't need to hunt down its exact location. Combine which and cat to read the source directly:

cat $(which make-mac.sh)

Why This Is Helpful

Quick inspection without searching - Instead of running find or locate, you immediately view the script that would actually execute when you type the command.

Verify before execution - Check what a script does before running it, especially important for scripts you didn't write or haven't used in a while.

Learn by example - Reading well-written scripts in your PATH is an excellent way to learn shell scripting techniques and best practices.

Debug PATH conflicts - If you have multiple versions of a script, which shows you exactly which one will run based on your current PATH order.

Copy and modify - Quickly grab a working script as a starting point for your own modifications.

Variations

View with syntax highlighting using less:

less $(which script-name)

Edit the script directly:

nano $(which script-name)
# or
vim $(which script-name)

Show the full path without viewing:

which script-name

Find all instances in PATH:

which -a script-name

What About Non-Scripts?

This technique only works for text files like shell scripts. For compiled binaries, you'll get binary output. Use file to check first:

file $(which command)

This simple command combination saves time and helps you understand your system better by making it easy to peek under the hood of any script-based command.