8

I know what dot files or folders are, but there is a specific dot named folder (the name is just a dot) in every directories. What are they used for?

For example here is a part of my "bin" folder. Look at the first tow lines.

drwxr-xr-x  2 root root 4.0K Jul 29 12:39 .
drwxr-xr-x 23 root root 4.0K Jul 29 12:37 ..
-rwxr-xr-x  1 root root 904K Mar 30 20:02 bash
-rwxr-xr-x  1 root root  30K Aug  3  2012 bunzip2
...
2

3 Answers 3

18

Every directory contains a . and a .. entry.

. means the directory itself. It is called the current directory.

.. means the directory's parent directory, that is, the directory that contains it.

There is one directory that is not contained by any other directory: /. So / is special--like all other directories, it contains a .. entry, but its .. entry is itself. So for /, and only for /, .. and . are equivalent.

These directory entries are handy for a variety of purposes. For example, you can change directory to the parent of the directory you're currently in with the command cd ...

You may have seen . in the context of running programs or scripts. In a Unix-style shell, when you run a command by name, the shell doesn't automatically try to run a program by the name in the current directory. (This is surprising to some users coming from Windows, where traditionally that would happen.) The main reason for this is security--if someone creates a program in their directory that has the same name as some system administration tool, and you run that tool while in their directory, they could have just tricked you into running their program.

So, to run a program that is not in your PATH, you must call it by some name that has a / in it. To run a program in the current directory, you can use ./program. (You cannot use /program, because that is an absolute path and means "the file called program in the root directory, /.")

2
  • Replacing just by only in the sentence So for /, and just for /, .. and . are equivalent. would rise accessibility to non-native English speakers.
    – Wolf
    Nov 13, 2020 at 10:39
  • @Wolf Thanks. I've made the change you suggested. Nov 20, 2020 at 20:40
1

The single dot represents the current directory. The double dot represents the parent directory. Typing "cd .." will take you to the parent directory. See the bottom of this page for more information: http://www.basicconfig.com/linux/linux_cd_command_tutorial

3
  • I thought the two dots in "cd .." is a special argument but it's a real directory
    – ziggurat
    Jul 31, 2013 at 20:00
  • .. isn't actually the name of a directory - actually it is a symbol that means "whatever directory is above this one". This symbol is recognized in the bash program, which is the shell we most often use in Linux when we open the terminal.
    – Richard
    Jul 31, 2013 at 22:20
  • @searchfgold6789 That's actually not true (at least not in Ubuntu or any other GNU/Linux OS; there may be some operating systems where what you're saying is the case). . and .. are real filesystem entries. They are not implemented by bash, nor by any other shell or shells or combination of userspace programs; they are implemented by the kernel, and are just as "real" as any ordinary directory, in the sense that if you write your own program that views the contents of a directory but doesn't know anything about . and .., it will see . and .. too. Jul 31, 2013 at 22:41
1

. means the current directory.

.. means the parent directory.

So when you type cd .. , you will move one level up. When you type cp /etc/resolv.conf . , you will copy file /etc/resolv.conf in the current directory.

Not the answer you're looking for? Browse other questions tagged .