Oct 8, 2011

The Tilde (~) in Unix and URLs

A tilde (Punctuation mark)
Image via Wikipedia
UNIX

In the Unix shell, the tilde (~) is an abbreviation for the path to your home directory. (It has other expansions but this the meaning when the tilde is used as a separate word.)

Tilde expansion is the process of converting the abbreviation to the path to the user's home directory.

Example (not using ~)

/home4/susanQ/public_html/111/ is the Unix path to Susan Queue's 111 folder on shell.uoregon.edu.

Example (using ~)

~/public_html/111/ is the Unix path to Suzie's folder on shell.uoregon.edu

Example

$ pwd
/tmp

$ cd ~

$ pwd
/home4/susanQ/

$ echo $HOME
/home4/susanQ/

(~ is a synonym for the value of the shell's HOME variable)

URLs

In a URL, the tilde (~) has a related but different meaning: it stands for the path to your public_html folder on the web server.

Example: 

URL:
http://uoregon.edu/~susanQ/

Corresponding Unix path on the server:
/home4/susanQ/public_html/

Example: 

URL:
http://uoregon.edu/~susanQ/111/
Corresponding Unix path on the server:
/home4/susanQ/public_html/111/

Enhanced by Zemanta