How the which Command Works on Linux
Let's look at how the which command works on Linux
Join the DZone community and get the full member experience.
Join For FreeWhen we are running servers, or even our local computer, different applications may install the same piece of software multiple times. For example, it is not uncommon to accidentally have two versions of Node.JS installed on a server or computer.
In the example where we have multiple versions of Node.JS, it can be confusing which versions are running, or which will be used when we run the node command in a terminal window.
If we want to know the origins of a command, we can use the which command to find where it is installed. The which command has the following syntax, [x]
, [y]
and [z]
are what we want to check:
which [x] [y] [z]
How to Use the which Command on Linux or Mac
Lets use our Node.JS example to start with. If we want to know which Node.JS is being used, we can simply type the following:
which node
This will then return something like this:
/root/.nvm/versions/node/v14.15.1/bin/node
Checking Multiple Commands With the which Command on Linux or Mac
If we want to check the location of multiple commands on Linux or Mac, we can use the usual which syntax, but just separate each item we want to check with a space.
For example, the below text checks both node, and postfix:
which node postfix
And for me, it returns this:
/root/.nvm/versions/node/v14.15.1/bin/node
/usr/sbin/postfix
Published at DZone with permission of Johnny Simpson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments