0

The tilde character ~ doesn't function as the home directory shortcut on Windows, unlike as on Unix systems. I've always used the character as the home path in written text for all operating systems and I wonder if this is factually wrong.

%USERPROFILE% may be more suitable as it can be used as an actual shortcut in the Windows Explorer.

Run5k
  • 16,463
  • 24
  • 53
  • 67
user198350
  • 4,269

2 Answers2

3

For most cases, you are correct (which is immensely maddening when I'm on my work computer).

One exception: PowerShell accepts use of the ~ character and it is expanded to your home directory if you use tab completion.

Third-party Bash installs (such as the copy that comes with Git) support ~ as well.

Broam
  • 4,084
3

The tilde character may have a totally different meaning in Windows, and I would consider it invalid – or at least ambiguous – to use it to refer to the user's home directory.

On file systems that do not support long file paths, the tilde would be used as a replacement character:

A long file name is considered to be any file name that exceeds the short MS-DOS (also called 8.3) style naming convention. When you create a long file name, Windows may also create a short 8.3 form of the name, called the 8.3 alias or short name, and store it on disk also.

[…]

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.

You can read more about 8.3 filenames on Wikipedia, which is a legacy file naming convention that dates back to the times of DOS.

That said, modern programs may indeed use ~ as an alias for the user's home – PowerShell for example, see @Broam's answer. And of course there is a difference between having the user type something that the shell then interprets vs. what a shell may output. However, as you cannot assume users to use PowerShell, or be knowledgeable about Unix conventions, I'd recommend against it.

slhck
  • 235,242