What does the ~ mean in an absolute file path?

I see this in the output of things like build scripts but the path does not exist.

link|improve this question
12  
Which operating system? – ChrisF Nov 16 '10 at 10:45
feedback

6 Answers

Normally it means the user's home directory e.g. ~mike/ would be the user mike's home directory, ~/ would be your own home directory. However, it is unclear to me whether ~/ and ~mike/ should be considered absolute or relative; it seems to depend on the definition given (if anyone can come up with an authorative reference, please post a comment).

Note that I'm talking about Unix based systems here.

See http://en.wikipedia.org/wiki/Home_directory#Unix

link|improve this answer
3  
They are absolute, because they are synonyms for absolute paths: on UNIX, the absolute path can be inferred from the contents of the /etc/login file. The expansion is traditionally done by the shell, but any language that has pretensions to be "scripting" will do this as well. – Charles Stewart Nov 16 '10 at 11:20
1  
+1: I didn't know about the ~username/ thing. – Wuffers Nov 16 '10 at 13:21
1  
Interestingly, Windows PowerShell also accepts ~ as a synonym for the user's home directoy. – Joey Nov 16 '10 at 13:51
Jeffery Snover has said that PowerShell was originally based around VIM/EMACs – Anonymous Type Nov 16 '10 at 22:21
@Charles Stewart arguably at least ~/ is relative as it depends on the users context. Also some references define a absolute path as one given from the root of the filesystem, which these obviously aren't. If you have a reference for your statement, please share! – Adrian Mouat Nov 17 '10 at 17:02
show 1 more comment
feedback

Actually, both of the answers by Adrian Mouat and studiohack are true.
In operating systems with limited naming convention (Older version of Windows/DOS etc') it signifies a long name.

e.g. "c:\program files\" is equivalent to "c:\progra~1\"

In some operating systems (namely Unix) it means home-dir (and might be seen as an absolute but not canonical path).
e.g."/a/vol01/usr/mike/" might be shortened to "~/mike/"
* where 'usr' is the home dir.

link|improve this answer
2  
In the context of build scripts, it is probably the Unix-centric version. – Charles Stewart Nov 16 '10 at 11:22
2  
Unix paths usually use forward-slashes rather than backslashes. – Torben Gundtofte-Bruun Nov 16 '10 at 13:52
@torbengb, true...opps – Xenorose Nov 16 '10 at 14:05
feedback

On many file systems, a file name will contain a tilde (~) within each component of the name that is too long to comply with 8.3 naming rules.

Source: Naming Files, Paths, and Namespaces - Short vs. Long Names - MSDN

(Part-way down the page...)

link|improve this answer
feedback

And if you do ASP.NET programming it means the top level of the website; rather than navigating using ../../images/some_image.jpg (and getting your nesting level wrong!) you can simply say ~/images/some_image.jpg

link|improve this answer
/images/some_image.jpg should take you to the root of any web site. What additional functionality does the tilde provide in ASP.NET? – Sonny Nov 16 '10 at 16:12
4  
~ takes you to the web application root which is not the same as the web site root if you're using a virtual directory. For example, if your website is installed on myserver in virtual directory myapp, ~/images/myimage.jpg will resolve to myserver/myapp/images/myimage.jpg. See msdn.microsoft.com/en-us/library/ms178116.aspx. – MCS Nov 16 '10 at 16:18
feedback

Here is a couple of hints that can help you to figure it out better:

$ readlink -f ~

$ echo $HOME

Note: $ is a convention to specify the user command line prompt, it is not a part of the commands.

link|improve this answer
feedback

I get the tilde in front of a file name that has been stored on an external device.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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