cmd equivalent to "cd ~" to change to C:\Users\<current user>\Documents\

Is there a shortcut for C:\Users\<current user>\Documents\?

There is no direct shortcut.

There are a couple of different solutions (see below).

  1. Use an environment variable together with cd or cd /d

  2. Use subst or net use to creating a mapping to another drive letter.

  3. Install cygwin and use bash

  4. Use powershell - powershell supports ~

The last solution is probably the simplest if you are prepared to use powershell instead of cmd.


Solution 1: Use an environment variable together with cd or cd /d

If you want to change to this directory on a regular basis then run the following command:

setx DOCS %USERPROFILE%\Documents

This will permanently set the environment variable DOCS, but in order to use use it you need to first start a new cmd shell, then the variable is defined and ready to use:

F:\test>echo %DOCS%
C:\Users\DavidPostill\Documents

To change directory from any location use the following command:

cd /d %DOCS%

If you are already on drive c: you can just use:

cd %DOCS%

Create a batch file (docs.cmd) and put it somewhere in your PATH.

docs.cmd:

@echo off
cd /d %DOCS%

You can then just type docs regardless of your current location and it will take you to C:\Users\<current user>\Documents\


Solution 2: Use subst or net use to creating a mapping to another drive letter.

You can use subst:

subst x: %USERPROFILE%\Documents

And then

x:

Unfortunately drive mappings do not persist across reboots.

net use will persist across reboots, for example:

net use x: "\\computerName\c$\pathName" /persistent:yes

See the answers in How to make SUBST mapping persistent across reboots? for detailed instructions.


Solution 3: Install cygwin and use bash

Only just started, already hate cmd

You could consider installing cygwin:

Cygwin is:

  • a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.

Once you have installed cygwin you can run bash in a cygwin terminal.

Alternatives to cygwin include msys (MingW):

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.

And Git for Windows:

Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.


Solution 4: Use powershell

As pointed out in a comment by SBI powershell supports ~ and you can just type:

cd ~/documents

If you have strange characters in your user name (for example if your user name is an email address) then quote as follows:

cd "~/documents"

But also I need to be able to run a shortcut!

However, to run Intel's icl, I require a shortcut to C:\Windows\SysWOW64\cmd.exe /E:ON /V:ON /K ""C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016.2.180\windows\bin\ipsxe-comp-vars.bat" ia32 vs2015".

Does powershell provide the necessary options as well?

You can create a shortcut as normal to run the above command.

Then execute the shortcut from powershell, for example:

 Invoke-Item -Path C:\Users\Dex\Desktop\Notepad++.lnk 

And:

 Start-Process -FilePath  C:\Users\DDhami\Desktop\Notepad++.lnk 

Source PowerShell trick : Execute .lnk file.


Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • cd - Change Directory - Select a Folder (and drive)
  • setx - Set environment variables permanently, SETX can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU).
  • subst - Substitute a drive letter for a network or local path.

Solution 5: Doskey

Not sure if you've been around since the dos days.. However, it's possible to overwrite command behavior using doskey macros. It's quite fun actually and doesnt require you to install any 3rd party software.

Here's a good example:

doskey cd=if "$1" equ "~" ( cd /d %userprofile%\Documents ) ELSE ( cd $* )

And a winning screenshot to go with it.

enter image description here


%userprofile% works to get to the user's profile folder - this way you do not have to specify the drive letter.

i.e. instead of using cd C:\%HOMEPATH%\Documents you can just use cd %USERPROFILE%\Documents