DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Move System Databases to Different Locations in SQL Server on Linux
  • Loop Device in Linux
  • Iptables Basic Commands for Novice
  • How to Install VPN on Linux?

Trending

  • Building AI-Powered Java Applications With Jakarta EE and LangChain4j
  • Building a Spring AI Assistant With MCP Servers: A Step-by-Step Tutorial
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  • Building Threat Intelligence Pipelines Using Python, APIs, and Elasticsearch
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. How the which Command Works on Linux

How the which Command Works on Linux

Let's look at how the which command works on Linux

By 
Johnny Simpson user avatar
Johnny Simpson
·
Mar. 21, 22 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
5.8K Views

Join the DZone community and get the full member experience.

Join For Free

When 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:

Shell
 
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:

Shell
 
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:

Shell
 
which node postfix


And for me, it returns this:

/root/.nvm/versions/node/v14.15.1/bin/node
/usr/sbin/postfix
Command (computing) Linux (operating system)

Published at DZone with permission of Johnny Simpson. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Move System Databases to Different Locations in SQL Server on Linux
  • Loop Device in Linux
  • Iptables Basic Commands for Novice
  • How to Install VPN on Linux?

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook