In Linux, we can go to the user home by entering the tilde (
~) character after
How to do the same in Windows?
Each time, I need to type:
cd C:\Document and Settings\freewind
That's too boring.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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 create a batch file called
@echo off cd /d %USERPROFILE%
And add it to your PATH variable (Start->[right-click on "Computer"]->Properties->"Advanced System Settings"[in left column]->"Environment Variables"
From there, just edit your PATH variable to include the folder containing your
~.bat file. (This allows you to invoke your script from anywhere using just the filename--not the absolute path to the file)
Also, make sure your
PATHEXT environment variable contains
.BAT somewhere (this allows you to type
~ instead of
When you need to use it, simply enter
~ at the command prompt. This solution is persistent--you won't have to set it up every time you launch a shell, and you won't need to hack your registry.
Unfortunately, I'm unaware of a perfect solution but there are a couple of hacky options:
Option 1: Set ~ to be a command alias with doskey
doskey ~=cd /d %USERPROFILE%
This will enable you to simply type
~ and have it chdir to your homedir.
Obviously, this shortens the number of keystrokes to get home (even compared to Linux), but is less robust since you can't really use it as part of another path or do much with it beyond just cd'ing home.
Option 2: Set ~ to be a variable
Another option, if you want a more robust option is to set a var:
but using this would be used like:
E:\>cd /d %~% C:\Users\a>
It can also be injected into most paths and doesn't limit you to simply cd'ing home.
Both options simultaneously
Also, you can implement both methods simultaneously. If you have the %'s around it, then it's going to utilize the variable - otherwise it will treat
~ as a command.
C:\>:: ECHO (display) THE VALUE OF %~% C:\>echo %~% C:\Users\a C:\>:: ChDir to ~\DESKTOP C:\>cd /d %~%\Desktop C:\Users\a\Desktop>:: USE THE ~ COMMAND C:\Users\a\Desktop>~ C:\Users\a>
One other tip (kinda related):
This is less likely to be acceptable on a corporate machine, at least on your home PC, to save additional keystrokes, it's not a bad idea to make your
%USERPROFILE% dir a simple name. As you can see from my examples above, my user dir is
C:\Users\a - I used to always have 'aplocher' or 'adamp' and when I changed to a single letter, it was magical.
Using PowerShell, you may try the following method to navigate directories from anywhere provided you know your username and have file directory permissions granted.
cd \..\Users\yourUserName\Documents cd \..\Users\yourUserName\Downloads cd \..\Users\yourUserName\Desktop cd \..\Users\yourUserName\music
See example below in PowerShell (64bit). I tested this on a Windows 7 Pro 64bit box.