How Does the Linux Built-in Command “which” Work when There are Two Files with the Name You Are Looking for in Different Directories in the $PATH Variable?

Problem scenario
You are using the "which" command.  You only get one result.  How does Linux choose the result when the file exists in two directories in the $PATH variable?

Run this command to see every directory in the $PATH variable:
echo $PATH

The "which" command evaluates from left to right and will return the first match found.

Leave a comment

Your email address will not be published. Required fields are marked *