Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create alias for a specific command in cmd

Tags:

alias

cmd

Is there anyway to create an alias to cd PATH command in cmd?

For example, instead of typing cd C:\John\Pictures I'd like to type just pictures in cmd and press Enter and it should simply take me to C:\John\Pictures.

Is that possible and how?

like image 949
Renya Karasuma Avatar asked Feb 25 '19 13:02

Renya Karasuma


1 Answers

You will need to use the doskey command which creates aliases, e.g.:

doskey shortcut=cd /d PATH

or specifically:

doskey pictures=cd /d C:\John\Pictures

Note that you mustn't quote the command like set: the quotes will included both in the macro and the command!

Another way to do that (more complicated) is to create a file named like your shortcut (e.g. pictures.bat) and insider put @cd /d C:\Jogn\Pictures and locate it in C:\Windows\System32 (or else in %windir%\System32; the same thing).

The other way as you mentioned in your comment, is to open cmd with a custom command, e.g. as you mentioned cmd.exe /K doskey pictures=cd /d C:\John\Pictures.

Note that /d option is important if you are in a different drive, so put it always with cd as it is good practice!

like image 148
double-beep Avatar answered Oct 20 '22 23:10

double-beep