What Does ./ Mean In Linux ?
For all the console enthusiasts
./ may seem quite familiar. It’s one of the many great things about Linux that makes it effortless to use from the terminal.
If you do not know what
./ means, we have got you covered. This article will explain in detail what does
./ in Linux means and what does it do in the Linux system.
./ to the point
The simple meaning of
./ is ‘Current Directory‘. It is as simple as this. But wait, it has more useful and interesting dimensions to it.
For all console enthusiasts, the small details in this
./ symbol, are very important and specific with the user hierarchy which may go unnoticed many times by a novice Linux user.
At any time when you are using Linux from the command line, you are located somewhere on the file system hierarchy. When you are working as a non-root user you are most probably located in your home directory.
Irrespective of what your current directory is you may require to handle files that are located outside your current directory. So changing the directory from time to time may be a tedious job. In order to make this easier, using
./ can prove to be an effective way to handle and modify multiple files from your current directory. You need not change the directories multiple times which will be a time saving and productive method.
Understanding ./ in pieces
Let’s try to understand the meaning of
./ in separate segments of
. (dot) and
. (dot):- With context to the question we are discussing in this article, the
. (dot) simply means the ‘Current Directory of the User‘.
gauravv@ubuntu:~$ ls -al total 179572 drwxr-xr-x 86 gauravv gauravv 266240 Sep 12 09:10 . drwxr-xr-x 4 root root 4096 Sep 4 18:29 .. drwxr-xr-x 2 gauravv gauravv 65536 Jul 15 2018 100CANON
In the above code, in the highlighted line you can see the dot
(.) at the end. This means that this is my current directory.
/ (slash):- When we append a
/ (slash) to the
.(dot) it simply makes sure that you are not operating on a file. It is same as appending
/ to any other directory name.
./ with an example
Let us take an example and understand the
./ with more clarifications.
Let’s suppose you wish to use the
nano text editor (a text editor for the console) instead of the Graphical text editor. You will be working on the console completely. When you start working with the editor you are placed in the Home Directory by default.
But suppose if the document that you wish to edit is in another directory. There’s a directory named space and here lies your document cool.txt. So the location path of this cool.txt file becomes ‘/home/gaurav/space/cool.txt‘.
To open this file in
nano, you certainly could type
[Directory_name_where_file_located] and then
But to make it more efficient and easy we can merely type
Look at the outputs below to better understand the example.
gaurav@ubuntu:~$ pwd /home/gaurav gaurav@ubuntu:~$
Here the Home Directory is ‘/home/gaurav‘. And the file to be edited (cool.txt) is located at ‘/home/gaurav/space‘.
But let’s say that I do not wish to change my current directory (/home/gaurav) and directly work from my home directory. I’ll do it as follows.
gaurav@ubuntu:~$ nano ./space/cool.txt GNU nano 2.9.3 ./space/cool.txt Modified Hi my name is tony stark i am a superhero.
gaurav@ubuntu:~$ cat ./space/cool.txt Hi my name is tony stark i am a superhero. gaurav@ubuntu:~$
Here I edited the file from my home directory itself without changing the path.
The main advantage of using
./ is that if you don’t wish to navigate away from your current folder, you can still manipulate files around you.
If you had typed only
nano cool.txt, you would be commanding
nano to open a file on the home directory (/home/gaurav) it would return an error as the file doesn’t exist in the home directory. And that’s the reason you use
Executing programs with ./
./ can be used to run the executable files of a program. We will understand this with an example.
If I want to run a C program in my
echo $PATH command to get your PATH), I’ll just compile the C program. On compilation, an executable file named
a.out will be created in the current directory. To execute this program I shall run the executable file
a.out. In order to run this C program, I shall just type
./a.out to execute the C program.
gaurav@ubuntu:~/space$ sudo gcc demo.c [sudo] password for gaurav: gaurav@ubuntu:~/space$ ./a.out gaurav@ubuntu:~/space$
In this context, prepending the command with
./ effectively says “forget about the PATH, I want you to look only in the current directory”.
Similarly you can instruct the system to look only into another specific location by prepending the command with a relative or absolute path such as:
../ means Parent Directory or
./work/demo.c which means that look for the file demo.c in the directory named work.
./“ is used in a pathname to indicate the current directory. It can also run a script from the current working directory. It’s a time saver practice to use ./ in your $PATH as it enables you to modify files that are not present in your current directory and that too without even leaving your current working directory.