The ~
character is a universal alias in the Unix word for referencing the home directory of the user. It is a special character that will be parsed and replaced by the full path of the current user's home directory. Is there an equivalent of this in cmd.exe ? (not Powershell)
1 Answer
No.
You can use commands like cd /D %homedrive%\%homepath%
or cd /D %userprofile%
but typing them is just not the same even if end result is. The closest to the simplicity of cd ~
I've ever seen is Señor CMasMas's elegant solution below.
Create a new bat file with one single line:
@cd /d %UserProfile% –
Save it with name cd~.bat
into any folder in your %PATH%. After that you can get from anywhere in the system back to home directory by typing command
cd~
-
13It is funny that you mention this. I have a
cd~.bat
file in my path that has one line in it..@cd /d %UserProfile%
Sep 23, 2021 at 2:18 -
1
-
6Be aware that
%homepath%
does not include the drive, just the path relative to that drive.%homedrive%
contains the drive letter. Sep 23, 2021 at 12:14 -
-
1In Unix you wouldn't even type
cd ~
, justcd
because$HOME
is already the default destination.~
is useful when you're cd'ed somewhere else and want to reference a file in your home dir, e.g.vim ~/notes.txt
orcp -a foo ~/bin/
. (Or in a script where you might be.) Anyway, isn't%homedrive%\%homepath%
basically equivalent to$HOME
, expanding an environment variable? When you say it's "not the same", do you mean it's too long to type? Sep 23, 2021 at 22:30
C:\Users\<current user>\Documents