Command aliases in Command Prompt?

How can I make command aliases in Windows' Command Prompt like I would with bash?

I found out about doskey in a forum thread, so I can do something like:

doskey ls=dir /b

...and now the command ls acts a little more like ls on Unix. (I type ls so often in cmd, it isn't even funny.)

But how do I get this to stick between sessions? It goes away the next time I open cmd.exe. (Is there something like .bash_profile?)


It is rather easy to setup permanent aliases in the Windows command prompt using the @DOSKEY command and HKCU\Software\Microsoft\Command Processor Autorun option.

Quick step-by-step guide:

  1. Create a new batch file, call it Alias.bat. Copy/paste the text below. TIP: I recommend creating a C:\Bin folder for all your command line tools.
  2. Open the register HKEY_CURRENT_USER\Software\Microsoft\Command Processor.
  3. Add an String Value named Autorun and set the value to absolute path of the Alias.bat file.
  4. Done.

This batch file will execute every time you open a command prompt.

Contents of Alias.bat

DOSKEY ls=DIR $* 
DOSKEY cp=COPY $* 
DOSKEY xcp=XCOPY $*
DOSKEY mv=MOVE $* 
DOSKEY clear=CLS
DOSKEY h=DOSKEY /HISTORY
DOSKEY alias=if ".$*." == ".." ( DOSKEY /MACROS ) else ( DOSKEY $* )

Now you can type alias (i.e DOSKEY /MACROS) to view the current list of aliases/macros.

To add new aliases for the current session only you can use alias name=command.


Also sort of off-topic -

Use PowerShell instead of the cmd.exe command line. The good news is that PowerShell has the equivalent of .bash_profile, and runs just like the cmd.exe command line. It comes with a built-in alias generation feature. The bad news is that there is a bit of a learning curve if you want to do anything more complicated than simple cmd.exe commands.

By the way, ls is defined as an alias of dir, right out of the box.


There is a registry entry at HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun which allows you to run a command when you start a cmd prompt. This includes a batch file.


I'll be a necromancer for a moment and raise this thread from the dead. It's answer was not satisfactory for me. I knew there was a better way. I dabbled at making and including bat files and trying to figure out how to get the spaghetti ball working well it didn't well. Anyway back to Google I went..

I did find this too How to add new DOS alias/commands and create a keyboard shortcut for an admin DOS It works great, it should work on 98-7 (kinda funny numbering system but hey it's windows). I hope it helps those on this thread and those Google sends this way.

This way is not as simple as Alias, and neither is doskey. Once setup this is about the same effort.

I'll also add that parts of this merged with Dennis Williamson's answer are much better. You can have shell environments for multiple versions of the same application, say php 4 for your old scripts and php 5 for your test server.

Anyhow this worked out much better for me.