Linux Commands

What does dot backslash mean in Linux?

As Linux users, we all have to turn to the Terminal at one point or another to carry out some system tasks, whether they may have to do with installing new programs or removing old ones. For those that are fond of using the command-line, slash operators will be very familiar. But those who are not have come to the right place as we will be discussing this feature in great detail in this article.

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.

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.

$ echo $PATH

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.

$ ls -al

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.

$ pwd

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.

$ nano ./sample/sample.txt

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.

$ cat ./sample/sample.txt

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.

$ printf '%s\n%s\n%s\n' 'I live because' 'The mountains do not laugh' 'And the worms do not sing.'

Thus, now we have demonstrated the purpose of both of the slashes.

Conclusion

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.

About the author

Zeeman Memon

Hi there! I'm a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.