Categories
Linux Tutorial Series

Linux Tutorial Series – 82 – The command path

Here is the video version, if you prefer it:

Let’s talk about a special kind of environment variable – the PATH variable, also known as the command path. (Ward, 2014)⁠ This variable stores all the places your operating system will look for executables. (“How to set your $PATH variable in Linux,” n.d.)⁠ To recall, executables are a type of a command (executable is another name for an “ordinary” program (just like Firefox)). What this means is that every time you modify or append something to your PATH variable, you are, in essence, telling the operating system: “Look for the executable in this directory as well”. If you have multiple directories containing the same executable, the operating system will take the first one it finds.

Here is how the PATH variable looks like:

mislav@mislavovo-racunalo:~/Linux_folder$ echo $PATH

/home/mislav/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/mislav/Python-3.7.4/bin:/usr/lib/jvm/jdk1.8.0_231/bin:/usr/lib/jvm/jdk1.8.0_231/db/bin:/usr/lib/jvm/jdk1.8.0_231/jre/bin:/home/mislav/Downloads/hadoop-2.10.0/bin:/home/mislav/Downloads/hadoop-2.10.0/sbin

I put $ in front of PATH to get the contents of the PATH variable. Here we see that all the folders where to look for executables are separated with a colon. So the structure of the PATH variable looks like this: path1:path2:path3

This is convenient for the operating system because it tells the operating system where to look for executables. Otherwise, it would have to search through the entire computer looking for your executable. Yikes! Better help the good ol’ operating system by telling it where to look for. 

Hope you learned something useful!

References

How to set your $PATH variable in Linux. (n.d.). Retrieved February 27, 2020, from https://opensource.com/article/17/6/set-path-linux

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 22-23

NewsletterUpdates on interesting things I am doing

Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.

Leave a Reply

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