What is double dot(..) and single dot(.) in Linux?

2019-01-03 17:22发布

The ls -ai command shows that . and .. have their inodes same as current directory and parent directory, respectively.

Could anyone tell me what exactly . and .. are?

Are they real files or even hard links? But as I have known, it's not allowed to create a hard link to a directory.

4条回答
够拽才男人
2楼-- · 2019-01-03 18:10

They are special name-inode maps which do count as hard-links (they do increase the link-count) though they aren't really hard-links, since, as you said, directories can't have hard-links. Read more here: Hard links and Unix file system nodes (inodes)

查看更多
神经病院院长
3楼-- · 2019-01-03 18:13

. represents the current directory that you are using and .. represents the parent directory of current directory.

example: Suppose you are in the directory /remote/speed3/users/devraj/ and you wanted to move to parent directory i.e. /remote/speed3/users then use cd..

/remote/speed3/users/dpawar> cd ..

and if you wanted to set path of one file in current directory bash file use . with file name like this ./filename

查看更多
趁早两清
4楼-- · 2019-01-03 18:22

. represents the directory you are in and .. represents the parent directory.

From the dot definition:

This is a short string (i.e., sequence of characters) that is added to the end of the base name (i.e., the main part of the name) of a file or directory in order to indicate the type of file or directory.

On Unix-like operating systems every directory contains, as a minimum, an object represented by a single dot and another represented by two successive dots. The former refers to the directory itself and the latter refers to its parent directory (i.e., the directory that contains it). These items are automatically created in every directory, as can be seen by using the ls command with its -a option (which instructs it to show all of its contents, including hidden items).

查看更多
孤傲高冷的网名
5楼-- · 2019-01-03 18:25

They are not hard links. You can more think it like a short hand for (.) this Directory and (..) parent of this directory.

try to remove or rename . or .. then you understand why it is not a hard link.

查看更多
登录 后发表回答