Ad space (banner)
🖥️Linux Lessons
Lesson 31 / 61

Finding a Command's Location with which

which is for when "I want to know exactly which file this command actually is." which shows the full path of the executable file that gets run for a given command.

Use it in the form which command-name. It's useful in an environment where several versions of the same-named command are installed, to check which one is actually used.

Running which grep shows the location of the grep command that actually gets invoked, something like /usr/bin/grep.

A common early mistake is not being able to tell, when nothing is shown because the command isn't found, whether the cause is "the command doesn't exist" or "it's simply not on the PATH."

In real work, this is used for environment troubleshooting — like isolating a bug caused by a version mismatch between two same-named commands.

Linux
Try it (type this into the pseudo terminal)
which grep

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)