Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Since ~, . and .. are special directories, why are they handled differently in the following example?

$ echo ~
$ echo ..
$ echo .
  1. ~ is expanded into the dir, but the other two are not.
  2. The other two are expanded literally, but ~ isn't.
share|improve this question
~ is not a directory, it is a construct of your shell and does not truly exist. – casey Jul 31 '14 at 16:08
. is not (the name of) a directory either, but ~ refers to your home directory as . refers to the current directory and .. refers to the parent directory. – iconoclast Jan 16 '15 at 3:02

~ is a special name expanded by the shell, . and .. are real proper directory names, so no expansion is done by the shell there.

share|improve this answer
For example, type ls -a and you'll see the . and .. directories. The only reason they're not usually shown is that anything beginning with . is hidden by default. – Useless Jul 31 '14 at 17:30
Another way to see the difference is to quote it: ls -ld '~' will give an error (unless there's a file of directory named ~ in the current directory) while ls -ld '.' will show information about the current directory. – celtschk Jul 31 '14 at 18:15
+1 Might also be useful to mention the fact that . is a hard link to the current directory and .. is a hard link to the current directory's parent. – Joseph R. Aug 24 '14 at 1:51
. is not a directory name, unless you issue mkdir '.' – iconoclast Jan 16 '15 at 3:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.