Is it something like they are by default added to every directory created to facilitate movement outside?
3 Answers
Leading dot filenames
Simple answer is because these filenames start with a dot. Any filename that starts with a dot is considered a hidden file on Linux (even if in this case the filename itself is just one character long) and is basically a "tradition" that goes back to first Unix OS . You can view them with ls -a
.
If you want to know why on the code level, it is set as default within ls.c
file of src/ls.c
in coreutils package:
638 static enum
639 {
640 /* Ignore files whose names start with '.', and files specified by
641 --hide and --ignore. */
642 IGNORE_DEFAULT,
643
644 /* Ignore '.', '..', and files specified by --ignore. */
645 IGNORE_DOT_AND_DOTDOT,
646
647 /* Ignore only files specified by --ignore. */
648 IGNORE_MINIMAL
649 } ignore_mode;
Simple applications
You asked:
Is it something like they are by default added to every directory created to facilitate movement outside?
Yes, since .
refers to directory itself and ..
refers to the parent directory. Exception is the /
directory which is the root of the filesystem tree. In that case, ..
refers to /
itself since there is no directory higher above it. Instead of memorizing each path, the convenience is that you can go up one level using cd ..
. Simple, right? Now imagine that you have a very long path. It is inconvenient to type full path to parent directory, whereas ..
is far simpler. It also allows for simple scripting such as this function I keep in by .bashrc
:
goup() {
num=$1
while [ $num -ne 0 ]
do
cd ..
num=$(expr $num - 1 )
done
}
By specifying goup 5
i can go up 5 directories, where each ..
refers to parent of a parent of a parent.
In case of .
it can be used by scripts to determine their current location, if that's ever necessary.
In other languages, utilities
Shells are of obvious attention. Their behavior is the same as of ls
, by default ignoring filenames when one uses glob
$ echo *
LICENSE README.md ayatana-indicator ayatana-indicator.desktop debian
star:
We can mimic ls -a
with shell glob if we add .*
to include hidden files.
$ echo * .*
LICENSE README.md debian indicator-bulletin indicator-bulletin.desktop .git .gitignore
By contrast some other programs/utilities and programming languages don't hide these items (or at least they don't hide .
). Their purpose, however, is much more extensive that merely listing directories, and they are far more suitable for parsing files (Please read Why you shouldn't parse the output of ls(1)).
$ find -maxdepth 1
.
./.git
./README.md
./LICENSE
./debian
./indicator-bulletin.desktop
./.gitignore
./indicator-bulletin
$ perl -le 'opendir(dh,$ARGV[0]);while( $file = readdir(dh) ){ print $file; }; closedir(dh);' "."
.git
..
README.md
LICENSE
debian
.
indicator-bulletin.desktop
.gitignore
indicator-bulletin
Python's os.listdir()
is notable exception - it doesn't show .
nor ..
. The glob
module can be used to show same behavior as in shells.
$ python -c 'import os;print(os.listdir("."))'
['.git', 'README.md', 'LICENSE', 'debian', 'indicator-bulletin.desktop', '.gitignore', 'indicator-bulletin']
$ python -c 'import glob;print(glob.glob(".*"),glob.glob("*"))'
(['.git', '.gitignore'], ['README.md', 'LICENSE', 'debian', 'indicator-bulletin.desktop', 'indicator-bulletin'])

- 105,154
- 20
- 279
- 497
In MS-DOS and Windows there are also .
and ..
. Quite simply .
represents the current directory and ..
represents the parent directory.
MS-DOS was born from CPM operating system when Bill Gates bought rights for $80,000 and licensed to IBM as PC-DOS which turned into MS-DOS which turned into Windows which is predicted to land him a Trillion Dollars in the end.
Linux also uses .
and ..
as the first file system version was based on IBM PC-AT hardware.
As Serg answered in Linux .
and ..
don't appear in ls
command because any file beginning with .
is a hidden file. You can use the ll
alias to see these files though.
In both MS-DOS and Linux you can use cd ..
command to change to the parent directory. In Linux when you want to call a command in the current directory (not in the path) you need to prefix the command with ./
. In MS-DOS however it will automatically look in the current directory for the command before searching the PATH.
Apple Mac and Google Android are based on the Linux operating system but I don't know if their file systems also use .
and ..
.

- 102,282
A file beginning with a .
is a hidden file. The hidden part is a convenience of providing the user with a cleaner output of what he may be looking to see.
Under normal circumstances, the user is looking for an output of files he'll be working with, such as word processor files, pictures, and other data on the system.
The -a
option is an argument to show ALL files. That includes the hidden files.
The hidden files are usually special files such as configuration and auxiliary files. You can see them by including All files, or hidden files in your output. The GUI file browser has a Show Hidden files option.
In this case of the files that are .
and ..
. They are the specification of your directory. The single dot is your current directory. The double dot is the parent directory. You can backup to the parent directory from where you are by typing:
$ cd ..
Just like the other files that begin with the dot, they are hidden. A person will specify show all to show hidden files if for they wanted to view those directory specifications.

- 25,036