I have to switch to Windows for the duration of a project.
I have only just started, and I already dislike using cmd.
Is there a shortcut for C:\Users\<current user>\Documents\ ?
I have to switch to Windows for the duration of a project.
I have only just started, and I already dislike using cmd.
Is there a shortcut for C:\Users\<current user>\Documents\ ?
C:\Users\<current user>\Documents\?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.
cd or cd /dIf 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\
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.
cygwin and use bashOnly 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.
powershellAs 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.
subst does not persist if you reboot. There is a workaround for this (see How to make SUBST mapping persistent across reboots?), but it requires 3rd party software or registry changes.
– DavidPostill
Mar 04 '16 at 11:34
~/documents needs to be in double quotes like this: cd "~/documents", otherwise it won't be expanded properly (for...reasons). The edit is too short for me to make.
– SBI
Mar 04 '16 at 12:26
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.
/d to the cd %userprofile%\Documents so it works even when on other drives.
– Ben N
Mar 04 '16 at 17:30
cd "WebCam Media" returns Media" ) was unexpected at this time..
– DavidPostill
Mar 04 '16 at 18:39
doskey.This shows Windows still uses the DOS command prompt
– Suici Doga
Mar 05 '16 at 03:04
cmd.exe is very much a Windows program, and is even 64-bit on 64-bit systems.
– Ben N
Mar 05 '16 at 21:54
%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
cd /d "%USERPROFILE%\Documents", of course.
– Luaan
Mar 04 '16 at 12:44
You can use %HOMEPATH%. It will take you to your home directory, just like the tilde does in linux. So to get to your desired location, the command is:
cd C:\%HOMEPATH%\Documents\
%HOMEPATH% instead of %USERPROFILE% could be a good idea with domain accounts using Folder Redirection.
– paradroid
Mar 04 '16 at 11:34
%USERPROFILE%,%HOMEPATH%setting a variable, doing a bat file, using MinGW... as in the others. Can we do other questions about how to change into the Desktop directory and so on? I hate to close questions it's against my nature :-) – Hastur Mar 04 '16 at 12:06cd ~in powershell works just like under unix. – SBI Mar 04 '16 at 12:14cd ~/documentsfor the OPs particular case. Adding to my answer. – DavidPostill Mar 04 '16 at 12:17C:\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? – User1291 Mar 04 '16 at 12:21man cdshowing the manpage forset-location). So I guess you could just give it a shot. – SBI Mar 04 '16 at 12:23cmd /cto execute some commands in that one which works for most circumstances (if environment variables are set in the child process you'll have to make sure to transfer them back afterwards - that's ugly but there's code somewhere on SO for that too. – Voo Mar 05 '16 at 15:26