How to set aliases for the command prompt in Windows

In this article, I would like to share with you a useful way to define aliases for the command prompt. The method described in this article works in all modern Windows versions including Windows 10, Windows 8.1, Windows 8 and Windows 7. By following the steps below, you will be able to define any desired alias to extend the functionality of the default command processor (cmd.exe) and save your time.

There is a doskey command available in the command prompt. Using doskey, it is possible to define an alias for a new or existing console command.
For example, almost all users are familiar with the cd command which is used to change the current directory in the command prompt. If the desired directory is located on another drive, you need to use the "/D" switch with the cd command or enter the drive letter in the command prompt explicitly.
For example:

d:
cd documents

or

cd /d d:\documents

Using DOSKEY, it is possible to save your time and define an alias which will allow you to omit the requirement to enter the drive letter and the /D switch. For example:

doskey cd=cd /D $*

The following are some special codes in Doskey macro definitions:
$T Command separator. Allows multiple commands in a macro.
$1-$9 Batch parameters. Equivalent to %1-%9 in batch programs.
$* Symbol replaced by everything following the macro name on the command line. We used it in our alias.
Now, we can compare the results without the alias and with the alias.
Without the alias, the cd command will not change the active drive:

With the alias created with DOSKEY, the command prompt will change the active drive and the current folder automatically:

This is very useful.

Using DOSKEY, it is possible to define your own aliases. For example, you can create the LS alias for the DIR command to use a common command for directory listing in Windows and Linux. As you may or may not be knowing, LS is a default file listing command in the Linux operating system.

doskey ls=dir

Or something like this:

Define global aliases in the Windows command prompt

The problem with aliases is that they work only for the command prompt instance where you have defined them. To avoid this issue, you can create a new shortcut to cmd.exe or even modify the default one. You need to add the following parameters after the cmd.exe part:

cmd.exe /k c:\apps\cmd\aliases.cmd

Here the file c:\apps\cmd\aliases.cmd is a regular batch file which contains the appropriate DOSKEY calls.

Besides the command prompt, Windows allows defining your own aliases for the Run dialog as well. Refer to the following article: Launch your favorite apps with useful aliases from the Run dialog

That's it. This is a very useful way to define your own command or change the behavior of default commands. I am using these aliases since a very long time. What about you? Are you using aliases in the command prompt or were you not aware of this feature?

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

7 thoughts on “How to set aliases for the command prompt in Windows”

  1. A very nice effort on your part. This is really excellent documentation. I recommend it for those who tend to keep their fingers on the keyboard.

    1. I’d forgotten all about doskey, What a great little tool

      btw when I navigated to your site I got a bitdefender warning about stopping the download of a pup….!! You or the site manager might want to disinfect your system

  2. doskey router=ping -t 192.168.8.1 < router ip

    run "router"

    or dns…

    doskey dns=ping -t 1.1.1.1 < DNS ip

    just networking shortcuts….

  3. you can change the register instead of the parm in shotcut like this:

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
    “AutoRun”=”%USERPROFILE%\\alias.cmd”

    from:
    https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt

  4. You can even store macro in specific file to load them with doskey:

    echo cd=cd /D $* > test.txt
    doskey /MACROFILE=test.txt
    C:\Users\CodeKiller>cd C:\Windows

    By the way did you know F7, ALT+F7, F8, F9 and ALT+F10 in Command-Line ? :-)

Leave a Reply

Your email address will not be published.

Exit mobile version
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.