Is there a shortcut for C:\Users\<current user>\
?
There is no direct shortcut.
There are a couple of different solutions (see below).
Use an environment variable together with cd
or cd /d
Use subst
or net use
to creating a mapping to another drive letter.
Install cygwin
and use bash
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%
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\
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>
Solution 2: Use subst
or net use
to creating a mapping to another drive letter.
You can use subst
:
subst x: %USERPROFILE%
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
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 and set the bash environment variable HOME
as appropriate.
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 on another question by SBI powershell supports ~
and you can just type:
cd ~
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.
7In Unix, there's no need for the tilde.
cd
with no arguments will change to your home directory. – coneslayer – 2010-07-28T12:08:59.393there was a question like this here on su, can't find it. – akira – 2010-07-28T12:59:07.153
1@coneslayer i know but to move a file from one directory to another you use the tilde. – classer – 2010-08-01T08:21:17.703
As simple as
cd %userprofile%
– subtleseeker – 2019-06-08T17:16:58.470You can use Windows Power Shell (on Win XP and later) which allows you to use ~ for the home directory. See also ----> https://stackoverflow.com/questions/9228950/what-is-the-alternative-for-users-home-directory-on-windows-command-prompt
– franz1 – 2019-10-04T09:53:25.217