Is there a shortcut command in Windows command prompt to get to the current user's home directory like there is in Linux?

Solution 1:

You can always put a .bat file somewhere in your %PATH% which does the path changing for you.

Solution 2:

Yes, you can use %HOMEPATH%, and %HOMEDRIVE%. These contain the full path of the user's home directory (without drive letter), and the drive letter, respectively.

There are quite a few other useful variables available, such as %OS% (Operating System), or %WINDIR% (Windows system directory). See Wikipedia: Environment Variables for a list.


Notes:

Actually, things are a bit complicated (as usual). There is also%USERPROFILE%, which does contain the drive letter, and is usually the same directory as %HOMEPATH% plus %HOMEDRIVE%.

The values of these variables, and which one is right for you, will depend on the Windows version and any changes by an administrator, as their values may be different (see e.g. the question Difference between profile and home path ).

Solution 3:

Two other options both of which can be added to a script and auto-executed in a similar manner to BillP3rd's answer.

It's two more characters but...

SET ~=%HOMEPATH%    
CD %~%

or...

CD %~%\Desktop

Or...

doskey ~=cd %homepath%
~

Of course you can't use this ~ in paths but as a quick "jump to my home dir" typing ~ Enter is pretty quick.

Solution 4:

sleske's answer is almost exactly right, but it doesn't always work.

If your home directory is on a network share setup as a mapped drive, run the following regardless of the drive of the current directory:

cd /D %HOMEDRIVE%%HOMEPATH%

The /D switch is necessary to allow cd to change drives.

Solution 5:

I created a .cmd file in a directory in my PATH and named it cd~.cmd. Its contents are:

@cd %HOMEPATH%

I can type cd~ from anywhere to get to my home directory, though it's not the same as cd ~ (note the missing space), but is close enough for me.