A short breakdown
Before we get into what dot backslash means in Linux, let us define some discussion points. All of these are crucial to understanding the dot slash feature, and we have taken it upon ourselves to walk you through all of it.
- What is PATH?
- What is the root directory?
- What is the difference between absolute and relative PATH?
- What does dot mean in Linux?
- What does slash mean in Linux?
So, without any further ado, let’s get into it.
What is PATH?
In Linux and other Unix-like systems, we use the command-line to run executable programs through commands. However, the shell does need to be pointed in the right direction by something to address our demands of running executables. That’s where the environmental variable PATH comes in.
PATH is an environmental variable responsible for telling the shell where to look for the programs (executable files) we want to run. This variable holds great significance in the operating system since it effectively increases the convenience and safety of the system.
Environmental variables are just a particular class of variables that hold modifiable values. Keep in mind that there is a subtle but important difference between the uppercase PATH and the lowercase path. The second one is simply the address of a directory or file in the system.
You can check the PATH variable by running the following command in the Terminal.
Now that we have covered some ground about the environmental variable PATH, we learn about the root directory to use these concepts in conjunction with our main topic.
What is the root directory?
This section will expand on the root directory without getting totally lost in the details of the Filesystem Hierarchy Standard (FHS) of Linux. It is closely related to the PATH variable we previously mentioned; therefore, a small discussion is needed.
The root directory sits comfortably at the very top of the Linux filesystem hierarchy. It contains every file and directory on your computer, including the libraries, boot files, binaries, user files, configuration settings, temporary files, and much more.
In short, the root directory serves as the general reference point for addressing files and directories in your computer.
Difference between absolute and relative path
Next on our list is the absolute and relative path. We will be using the concepts mentioned above of root and path to determine the difference between the two.
An absolute path is a file or directory location concerning the root directory, not the current directory. Therefore, the complete address of a file in the computer is referenced by the root directory. The absolute path contains all the necessary information about the file or directory it is describing.
On the other hand, a relative path is used to describe a file/directory location concerning the current directory. It does not trace the address of a file from the root directory, rather from where you have set the current directory.
What does dot mean in Linux?
Dot, or “.” addresses the current user directory. Through this feature or operator, you can find where the current directory is set. Let’s see how we can achieve that as well.
Open a new Terminal window through the Activities menu or hit Ctrl + Alt + T on your keyboard. The next step is to execute the command given below.
You can see that in the output, the current user directory is highlighted by the line ending with a dot.
With that being said, we are halfway through understanding the purpose of dot backslash in Linux. Let us move on to the next section to discuss two types of slash operators (forward and back).
What does slash mean in Linux?
As mentioned earlier, there are two types of slashes, both with completely different purposes. Therefore, we must draw a clear distinction between the two.
The forward slash, /, when appended to the end of a dot, makes sure that you are not operating on a file. The same happens when adding a slash to the end of the name of a directory. Let’s take a look at how you can use it with a dot.
First, we check our home directory by the following command.
We are going to place a sample text file in the folder /home/sample/. We can use dot slash to do this without changing the current directory.
Note that our sample text file was accessed and modified without us having to change the current directory. Next, we can check the changes we made through the cat command.
And now, we get the output as:
To conclude the story of “./”, we can say that it allows us to address the current directory. So, we can also use it on our PATH variable to access files that are not in our current directory without ever leaving the current directory.
Next, we have the backslash, \. In Unix systems, and even some programming languages like C, the role of the backslash is to indicate to the system that the next character has a special meaning. Therefore, it works as an escape character. For example, a lowercase n, when used with a backslash, \n, indicates a new line character. Many other characters can be used instead of n to achieve different tasks. Let’s implement this in our Terminal. Here, %s is the string placeholder, \n is the newline character, and the rest of the three lines are the strings inputted to the placeholders.
Thus, now we have demonstrated the purpose of both of the slashes.
In this article, we went into great detail about the dot backslash feature in Linux. We learned the basic concepts of PATH, relative and absolute paths, the root directory, dots, slashes, and finally, how they are implemented in conjunction with each other.