Create alias in windows

Create command-line alias in windows

Aug 21, 2019 · 2 min read

Many time we need to use the same commands all-time in the terminal example:

  1. change directory to a long path like-

2. Open your server ssh terminal every time you need to run ssh commands like —

We can set an alias to quickly execute to a particular command like-

But as we close the terminal so it would not work any more. How to make it permanent.

  1. Create a batch file here we can write Doshkey commands

2. Copy command prompt shortcut to desktop/ any location you want —

3. Rename it to any name — alias

4. now provide a path of the batch file to this shortcut by —

a. right click on icon select properties -> shortcut

b. In target give space and add

Done. Now you can easily access your all alias by opening this shortcut

You can now put any number of alias in .bat file

Plea s e give a clap if you like this post. Also, write in the comment section.

Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK. Love to write cool stuff

Aliases in Windows command prompt

I have added notepad++.exe to my Path in Environment variables.

Now in command prompt, notepad++.exe filename.txt opens the filename.txt . But I want to do just np filename.txt to open the file.

Читайте также:  Linux kernel development third edition

I tried using DOSKEY np=notepad++ . But it is just bringing to the forefront an already opened notepad++ without opening the file. How can I make it open the file?

16 Answers 16

To add to josh’s answer,

you may make the alias(es) persistent with the following steps,

  1. Create a .bat or .cmd file with your DOSKEY commands.
  2. Run regedit and go to HKEY_CURRENT_USER\Software\Microsoft\Command Processor

Add String Value entry with the name AutoRun and the full path of your .bat/.cmd file.

For example, %USERPROFILE%\alias.cmd , replacing the initial segment of the path with %USERPROFILE% is useful for syncing among multiple machines.

This way, every time cmd is run, the aliases are loaded.

For Windows 10, add the entry to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor instead.

For completeness, here is a template to illustrate the kind of aliases one may find useful.

  • Note that the $* syntax works after a directory string as well as an executable which takes in arguments. So in the above example, the user-defined command dropbox research points to the same directory as research .
  • As Rivenfall pointed out, it is a good idea to include a command that allows for convenient editing of the alias.cmd file. See alias above. If you are in a cmd session, enter cmd to restart cmd and reload the alias.cmd file.

When I searched the internet for an answer to the question, somehow the discussions were either focused on persistence only or on some usage of DOSKEY only. I hope someone will benefit from these two aspects being together here!

Оцените статью