What Is Double Dot (..) And Single Dot (.) In Linux?


Abstract

Linux terminal/Shell contains several instances where a dot (.) is utilized. When displayed in the output of a command, a dot would also convey some significance. This article will examine the various situations in which a dot is typically used in Linux and the additional locations where this might be shown.

Double Dot (..) and Single Dot (.)

Example

$ ls -laxo

Output

Total 892
drwxr-xr-x 122 tutorial article 48 18 Dec 05:07 ./
drwxr-xr-x 54 tutorial article 4096 16 Dec 04:03 ../
-rw-rw-rw- 19 tutorial article 960 02 Dec 09:57 operations

In the following example, we will see how to copy all the files from a particular directory /tmp to the current directory using a single dot (.),

Note − Here (.) represents the current directory and don't forget to give the space between cfg and (.).

Example

$ cp /tmp/*.cfg . $ pwd $ ls

Output

/tmp/etc
sample.cfg Read.cfg figures.cfg
modules.cfg linux_tut.cfg fedora_23.cfg

To create a hidden file or directory

Any new directories or files can be created by prefixing them with a dot (.) and made hidden from the normal listing of files and directories.

In the following example, we will create a hidden file named .confidential.py using touch,

$ touch .confidential.py

We can also create a hidden directory by prepending the directory with a dot (.).

$ mkdir .open_source

To get a clear differentiation between visible and hidden files, we create a file named clear.py

$ touch clear.py

After giving the command “ls -l” command, the output shows only the visible files not the hidden files,

$ ls -l

Output

-rw-rw-rw-rw- 7 article article 0 Dec 25 clear.py

In the below example, we will use the command “ls -al” command which will all list the hidden files and directories,

Example

$ ls -al

Output

drwxrwxrwx 1 article article 512 Dec 4 11:53 .
drwxr-xr-x 1 article article 512 Dec 3 17:09 ..
-rw-rw-rw- 1 article article 0 Dec 3 02:35 .confidential.py
drwxrwxrwx 1 article article 512 Dec 3 22:37 .open_source
-rw-rw-rw- 1 article article 0 Dec 4 01:34 clear.py

Navigating through the directories

The "cd" command can be used to navigate through the directory hierarchy in a Linux terminal.

In the below example, after giving the “pwd” command it is observed that we are currently in the directory /tmp. The “cd..” command is used to navigate one directory level up which will lead us to directory /linux_files and the “cd../..” command is used to navigate two directories level which will lead us to directory /tutorials and continue.

Example

$ pwd

Output

/home/tutorials/linux_files/tmp

To navigate to the previous directory, we will use cd..

Example

$ cd..

Output

/home/tutorials/linux_files

Conclusion

In this article, we learned about Double Dot (..) and Single Dot (.) use cases. First, we saw the actual use of double dots and single dots, then we saw how these dots are useful to create a hidden file or directory, and at last, we saw how to navigate between directories using these dits.

These are the several scenarios where Double Dot (..) and Single Dot (.) are used in Linux. I hope you find these examples of the commands useful and that it's easy to learn and use Linux.

Updated on: 19-Dec-2022

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements