Creating an Alias

To create an alias in a windows environment or a BATCH script, we can open up a CMD or Powershell instance.

The structure of an alias is as follows:

doskey parameters  [shortcut command] = [commands to be executed]

A simple alias in BATCH scripting will look something like the following:

doskey cdoc = cd  C:\Users\Admin\Documents

We use the keyword doskey to create an alias, the alias is simply created by specifying the shorthand command in this example the word cdoc and the final piece of information is the actual command we want to replace with this alias. Thus when we create this alias, the command cdoc executes the command cd C:\Users\Admin\Documents and hence we optimize and create a shortcut to save some time and effort.

This will create an alias for this CMD/Powershell instance only, once you exit the session or window the alias is no longer working and hence was a temporary alias.

Batch Script – Aliases

Be it Linux, macOS, or Windows, we sometimes need to use the terminal or the command line to perform certain commands. If in such situations, we find ourselves repeating a few long commands we can use an alias to save time and make it easier.  In windows, we can create an alias as a batch command from the command prompt or the Powershell. We will see how to create and work with an alias in Batch scripting.

Similar Reads

What is an Alias?

Alias is a shorthand command to replace another command. We can think of it as a shortcut command for multiple or long commands. It can be also understood as a map of the shortcut keyword command with the actual command. The shortcut command is replaced with the string of commands which gets executed....

Creating an Alias

To create an alias in a windows environment or a BATCH script, we can open up a CMD or Powershell instance....

Creating a permanent alias

To create a permanent alias, we can specify these same commands of doskey in a .bat file which is also known as the Batch script or file. After the batch script/file is created with the alias you required we can copy the path of this batch file and add it to the CMD/Powershell target to add the alias in the initialization of those environmental shells(CMD/Powershell)...

Replacing an Alias

To replace an alias in a batch environment, we can simply edit the shortcut name to the command we want to replace with....

Deleting an Alias

To disable or delete an alias is quite straightforward. We can set the shortcut alias command to empty and the Shell environment will not consider it as a valid command anymore....

Options/Parameters in Batch Aliases

We can use certain parameters and options in the alias to integrate certain features that can be more used to make the alias more flexible....