Linux Command Locating

LinuxLinuxBeginner
Practice Now

Introduction

In the mystical landscape of ancient civilization, amongst the ruins of a grand temple, an annual ritual to appease the gods of technology is about to take place. The High Priest of the Order of the Code, an esteemed figure revered for their profound knowledge and connectivity with the divine forces of computation, is in dire need of an adept apprentice.

The temple's ritual, known as "The Invocation of the Hidden Commands," is a time-honored tradition where the command knowledge of the apprentices is tested. For this yearโ€™s ceremony, the High Priest seeks an apprentice who can demonstrate mastery in locating commands within the vast labyrinth of the Linux operating system, a skill crucial for maintaining the sanctity of the temple's ancient scripts. To gain the favor of the High Priest, one must navigate through the tasks of locating Linux commands with precision and grace.

This is your opportunity, young apprentice, to show your worthiness. Your mission is to use the which command, a powerful divination tool, to unearth the correct paths of the sacred commands that run the temple's machinery.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux/FileandDirectoryManagementGroup -.-> linux/which("`Command Locating`") subgraph Lab Skills linux/which -.-> lab-271443{{"`Linux Command Locating`"}} end

Basics of Command Locating with which

In this step, you will get familiar with the which command. which is a simple yet powerful command used to locate the executable file associated with a given command in your PATH. Knowing the path of an executable is necessary when you want to ensure that you are using the version you expect, or when configuring system settings.

Here's an example of how to use which:

which ls

When you run this, you should see the path of the ls command. Typically it would be /bin/ls.

Before running which, ensure that you are in the correct directory:

cd ~/project

It is important to remember that which only locates executables that are in your PATH. It will not find executables that are not marked as executable or are not located in the directories listed in the PATH environment variable.

Locating Multiple Commands

Now that you know how to locate a single command, let's look at how to find the locations of multiple commands at once.

which ls pwd cd

This will print the paths of the ls, pwd, and cd commands. Remember that cd is a shell builtin command and may not return any path because it's not an external executable.

Suggection: ls, pwd, cd need sort by the front to the back. if you don't do that, you will get the wrong answer in the verify script.

Summary

In this lab, we have explored the ancient technique of command locating with the which command within the Linux operating system. This skill empowers you as an apprentice to not just invoke commands but to also understand their origins. You've learned not only how to use which for a single command but also for multiple commands simultaneously.

Other Linux Tutorials you may like