What is the equivalent of Linux's "~" (tilde) in Windows?
In Linux, we can go to the user home by entering the tilde (~
) character after cd
:
cd ~
How to do the same in Windows?
Each time, I need to type:
cd C:\Document and Settings\freewind
That's too boring.
cd /d "%HOMEDRIVE%%HOMEPATH%"
would do it -- but I 'm not sure if you consider it an improvement.
You can also define an alias for the above command:
doskey cdhome=cd /d "%HOMEDRIVE%%HOMEPATH%"
After this, it's simply cdhome
.
You can use cd /d %USERPROFILE%
if you use cmd.
or you can use cd ~
if you use PowerShell.
One possibility is to use the subst
command from a command prompt:
subst z: C:\Document and Settings\freewind
Any time you navigate to drive Z:, you'll be looking at your user folder.
The downside is that you need to run it every time you log in. I used a batch file and just put it in my startup folder, but there are probably more elegant solutions to this.
The benefit is that unlike a doskey alias, it works universally (windows explorer, browse dialog, etc.), not just when changing directories at the command prompt. It's especially helpful for old programs with old browse dialogs that have drive letters at the topmost level, rather than "desktop".
You can do this:
cd %homepath%