Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am used to using

cd ~

to get right into my home directory. In windows command prompt I have to do

cd Users\username

to get there. Is there a shortcut like the Linux one? It would be nice if I could get there by doing

cd username

Any ideas on how to do this in Windows Vista?

Thanks,
Adam

share|improve this question
1  
In Unix, there's no need for the tilde. cd with no arguments will change to your home directory. – coneslayer Jul 28 '10 at 12:08
    
there was a question like this here on su, can't find it. – akira Jul 28 '10 at 12:59
1  
@coneslayer i know but to move a file from one directory to another you use the tilde. – classer Aug 1 '10 at 8:21
up vote 7 down vote accepted

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

share|improve this answer

Dunno if its a feature of our work login script or a windows default, but I can use cd %HOMEPATH% to achieve that, where HOMEPATH is an environment variable.

share|improve this answer
    
I see. It still takes a lot to write %HOMEPATH%. Also you can't auto-complete it. Is there a way I can make my username be equal to %HOMEPATH% by making a new command in cmd.exe? – classer Jul 28 '10 at 12:03

Yes, you can use %HOMEPATH%, which is the full path of the user's home directory.

There are quite a few other useful variables available, such as %OS% (Operating System), or %WINDIR% (Windows system directory). See e.g.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true

for a list.


Notes:

Actually, things are a bit complicated (as usual). %HOMEPATH% only contains the path, without the drive letter, so will not work for cding from a different drive. You can also use %USERPROFILE%, which does contain the drive letter, and is usually the same directory as %HOMEPATH%.

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 ).

share|improve this answer
2  
This is the most correct answer, in my opinion, because it does not rely on hard-coded paths and any wacky filesystem links that may be between them. – Ed Orsi Mar 11 '14 at 16:57
1  
This is the correct answer. – Frederik Krautwald Jun 3 '14 at 22:30
1  
This should be the accepted answer – mastazi Dec 20 '15 at 22:11
    
This saved my life! After looking at a lot of other answers from different questions. Again! This worked for me and should be the marked as the answer for this question. – Miss Lucy Jan 25 at 6:43
    
@MissLucy: I'm happy it helped you. As to accepting an answer: That's up to the OP to decide. You could add a comment to the question to alert them. – sleske Jan 25 at 9:39

If you want all user's commmand prompts to start in their "home" directory, create the following registry key as an Expandable String Value (sans quotes, of course):

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun : "cd /d %USERPROFILE%"

If you want only your command prompts to do it:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun : "cd /d %USERPROFILE%"

I make it a practice to keep a c:\Scripts folder in which I keep an "autoexec"-type batch file which I invoke via this key.

share|improve this answer

Windows has really become 'All about the gui' so in your case I'd just get the tools you want instead of trying to 'bend' the system to your will ... The MinGW tools are an excellent little collection of some of the most widely used gnu tools ... I highly recommend it if your a nix fan on Win ...

http://www.mingw.org/wiki/MSYS

share|improve this answer

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.

share|improve this answer

I created a .cmd file on a directory in my path, and named it "cd~.cmd". Its contents are:

@cd %HOMEPATH%

So I can type "cd~" from anywhere to get to my home directory. Not the same as "cd ~" (note the missing space) but close enough for me.

share|improve this answer

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.

share|improve this answer
1  
How about cd /d %homedrive%%homepath% as a one-liner? – james Jul 31 '14 at 19:51

I realize this is a long since done question, but just for the record. Install clink, this extends your command prompt in so many ways. Yes it it heavier then the above solutions but it makes the cmd window behave so much better.

share|improve this answer
    
clink == powerful Bash-style command line editing for cmd.exe – suspectus Feb 20 '15 at 14:29
    
Right, and the whole point is that ~ resolves to the User\{user} directory. – THBBFT Feb 20 '15 at 14:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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