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?)

  • Sorry to make it offtopic, but you can benefit from installing a copy of cygwin and have all the unix tools at your palmrest – bubu Jun 8 '10 at 18:06
  • Yeah, I'd like to, but I don't think that's an option (and might be more work than it's worth). My primary machines are Linux and OS X -- I'm just testing some programs on Windows right now. – Benjamin Oakes Jun 8 '10 at 18:10
  • 1
    there isn't much thing to do. cygwin.com/setup.exe is all you need to install. just download and click next. it's all there and very simple. there isn't much to configure either. – bubu Jun 8 '10 at 18:18
  • Hrm... well, I'll try it out. The machine has a lot of problems already though... ;) – Benjamin Oakes Jun 8 '10 at 18:40
  • 4
    unless your MS-DOS is version 6.22 or less, you aren't running DOS. by your mention of cmd.exe i assume you're talking about the basic WinNT/2k/XP/etc command shell. – quack quixote Jun 8 '10 at 18:56

10 Answers 10


cygwin can be used in this case although this is not exactly an on-topic answer.

http://www.cygwin.com/ CygWin
Download: http://cygwin.com/setup.exe

To access it easily in windows, you can put c:\cygwin\bin in your path.

note that there are a few command that clashes with windows software which is not equivalent e.g. find(1) vs find.exe -- find(1) lists all files and subdirectories whereas find.exe functions like grep.

another option is to access

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

check out

 cmd.exe /? 
for more details

| improve this answer | |
  • Hrm... it doesn't seem to use any of my Windows path... I'll have to play around with this later, I think. (Never used cygwin seriously before.) Thanks for your help so far. – Benjamin Oakes Jun 8 '10 at 19:10
  • adding the cygwin path into the windows path environment variable allows you to use the tools in the cygwin environment in cmd.exe; just note that there ARE caveats e.g. find.exe clashes with find command provided by cygwin. – bubu Jun 8 '10 at 19:15
  • Why the undervote? I just have no idea. – bubu May 31 '11 at 19:01

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 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.

| improve this answer | |
  • 1
    Simple, easy to update once setup, I like this one a lot! – Urda May 31 '11 at 14:22
  • Unfortunately I have since stopped using these alias, as the @DOSKEY command causes a crash when exiting Autodesk Maya 2010. There is probably a work around, e.g. checking if parent process is Maya, however I have not spent time investigating. – Dennis Jun 3 '11 at 13:20

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.

| improve this answer | |
  • Why did no one ever tell me to use power-shell before? It is so much better for so many things. – Andres May 15 '13 at 23:53

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.

| improve this answer | |
  • You may want to point to HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun as others will not have the same user ID as you. – bubu Jun 8 '10 at 19:17
  • @bubu: Oh, very true, sorry. I found that by searching my registry, didn't think. – Phoshi Jun 8 '10 at 19:21

I suggest installing dos versions of these commands directly from this link.

Simple, light, efficient etc. Been using it for a while now, Makes me happy! Cygwin is a bit big for the essentials I need.

| improve this answer | |

Try putting them in autoexec.bat. I'm not sure, you'll have to try it. Put autoexec.bat itself in C:\

| improve this answer | |
  • Doesn't seem to work... – Benjamin Oakes Jun 8 '10 at 18:19
  • autoexec.bat only works on dos/freedos systems. Windows 98 and up use the NT kernel instead of the dos kernel thus would not support autoexec.bat. One would have to add a shortcut somewhere's on the desktop with the parameters /K 'path\to\autoexec.bat' for it to remotely simulate the functionality – Dwight Spencer Apr 11 at 20:08

Put your aliases into a file called, perhaps, alias.cmd and add /K \path\to\alias.cmd to the shortcut that you use to start cmd.exe.


| improve this answer | |

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.

| improve this answer | |

Solving it by setting a PATH environment

create ls.c file

enter the following code

int main()
system("dir /b");
return 0;

into ls.c and compile the file:

$gcc ls.c -o ls

an executable file ls.exe is created

make a directory, name it as cmdline_tools

$mkdir cmdline_tools

copy ls.exe to the directory

set the path of the directory in PATH environment [copy the location of the directory and paste it in the PATH]


Open your cmd.exe and type


It works as dir command. You can do for other commands too in the same way. If not let us know.

| improve this answer | |

CMD with aliases/functions from doskey and bashrc (from cygwin>bash), forward slashes also work in cmd (win7 onwards)

  1. Create shorcut to cmd to use cmdrc.cmd

    cmd -a "/k %HOME%\cmdrc.cmd c:\ "

2 C:> cat %HOME%/cmdrc.cmd

:: Override same named builtin windows commands
:: To override these aliases, prefix with '@', eg. @date will not use alias.
@doskey date=c:\cygwin\bin\date.exe $*
@doskey echo=c:\cygwin\bin\echo.exe $*
@doskey mkdir=c:\cygwin\bin\mkdir.exe $*
@doskey rmdir=c:\cygwin\bin\rmdir.exe $*
@doskey find=c:\cygwin\bin\find.exe $*
@doskey time=c:\somedir\time.exe $*

:: using a particular rsync with some options
@doskey rsync=c:\cygwin\bin\rsync.exe -e "ssh -F %HOME%/.ssh/config" $*   

@doskey cp='cp -vi %*'
@doskey ..=cd ..
@doskey ...=cd ../.. 

:: Or use bashrc (bash aliases, bash functions):

:: eg. In bashrc we have "alias cpvi='cp -vi'"

@doskey cpvi=bash -ic "set +u; cpvi $*"  

:: now cpvi is callable from cmd.

:: Install clink_x64 if you want readline editing in cmd
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.