Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

$ echo ~
/home/tim
$ 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
8  
~ is not a directory, it is a construct of your shell and does not truly exist. –  casey Jul 31 at 16:08

1 Answer 1

~ 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
4  
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 at 17:30
3  
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 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 at 1:51

Your Answer

 
discard

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.