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
Newsletter
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

  • Five Common Time-Series Queries Made Simple With Enterprise Java
  • Fast Service but Slow Client: When a Sidecar Makes Sense
  • Designing a Data Pipeline for Multi-Location Marketing Attribution (Before You Actually Need One)
  • Building a Self-Healing Docker CI Gatekeeper With BuildKit

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Mar. 21, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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