Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used to work on bash and benefit a lot from alias. Is there any equivalent way in Windows Command Line?

I don't want to simulate a Linux environment, so cygwin is not a choice. I just need some shortcut for some very long command, like cd a_very_long_path.

share|improve this question

migrated from Mar 4 '13 at 9:53

This question came from our site for professional and enthusiast programmers.

You would use doskey (don't be fooled by the name it is not the old MS DOS doskey). Use doskey /? for more information. Other than that, I'm afraid, this question is off topic here. – Christian.K Mar 4 '13 at 7:42
Great comment, thanks. @Christian.K – StarPinkER Mar 4 '13 at 7:44
Possible duplicate of Is there a command to change path from current location to default directory, in Windows command prompt? Specifically, see my answer to know how you can have your DOSKey macros be auto-loaded when the Command Prompt is opened. – Karan Mar 4 '13 at 18:22
related + a way to make doskey permanent… – laggingreflex Aug 4 '14 at 5:52
up vote 30 down vote accepted

As Christian.K said in his comment, the DOSKEY command can be used to define macros, which are analogous to aliases.

doskey macroName=macroDefinition

Macro parameters are referenced in the definition via $ prefixed positions: $1 through $9 and $* for all.

See the doskey technet documentation, or type doskey /? or help doskey from the command line for more information.

But there are serious limitations with DOSKEY macros:

  • The macros only work on the interactive command line - they do not work within a batch script.
  • They cannot be used on either side of a pipe: Both someMacro|findstr '^' and dir|someMacro fail.
  • They cannot be used within a FOR /F commands: for /f %A in ('someMacro') do ... fails

The limitations are so severe that I rarely use DOSKEY macros.

Obviously you can create batch scripts instead of macros, and make sure the script locations are in your PATH. But then you must prefix each script with CALL if you want to use the script within another script.

You could create simple variable "macros" for long and oft used commands, but syntax is a bit awkward to type, since you need to expand the "macro" when you want to use it.


set "cdMe=cd a_very_long_path"

Usage (from command line or script)

share|improve this answer
Thanks, then is there any way to work within a batch script? – StarPinkER Mar 4 '13 at 12:19
@JermaineXu - No way with DOSKEY macros. See my updated answer for crude alternatives. – dbenham Mar 4 '13 at 12:31
The pro of the second solution is that, piping will work. The first solution with doskey will not work when you want to use the macro in piping. – Unhandled Exception Dec 20 '14 at 8:39
@UnhandledException - You are right! I never thought to test that since lack of batch support was enough for me to avoid DOSKEY macros. They also cannot be used as a command within FOR /F IN() clause. – dbenham Dec 20 '14 at 13:01
@UnhandledException - I've updated my answer to include your info. Thanks. – dbenham Dec 20 '14 at 13:12

You can make a batch script and save it into your path.

On Linux you would make a script and add it to the folder ~/bin on windows you can do the same.

Add %USERPROFILE%\bin to your PATH environment variable. Then save your scripts in there.


@echo off
cd a_very_long_path

Now you can type quickcd at the command line.

It can also be called inside a script using the call function

call quickcd
share|improve this answer


If you're really trying to get around something like this:

c: cd \users\myLoginID\documents\clients\MTV\strategy\roadmap\deliverable\final

you can use the subst command to map that long path to a separate drive letter

subst m: c:\users\myLoginID\documents\clients\MTV\strategy\roadmap\deliverable\final

Then, when you want to jump into that folder, you can just type m: at the command line.

The advantage of this over doskey is that it works in all batch programs, and shows up in any file dialog box within Windows.

If you don't want the mapping any more:

subst m: /D

share|improve this answer
If I could vote you more than one...:) perfect solution... – Anindya Chatterjee Apr 5 '14 at 21:17
I also like this but it DOES eat up drive letters. – GGB667 Sep 11 '14 at 21:10

You could use the same trick, that windows uses: set an environment-variable (or just a variable in a batch-context) for example there is an environment-variable %windir% (and some others) So you can do an

cd C:\Windows\


cd %windir%

which does the same. So all, you have to do is:

set "mydir=C:\very\long\path\to\my\data\"

after that you can do (from whereever you are):

dir %mydir%


cd %mydir%

or whatever you want.

share|improve this answer
That is the ticket @stephan ! – jbchurchill Sep 23 '14 at 13:40

I've made an "alias" like that specifically for changing directory. Basically I created a file named fav.bat and put it into a folder in PATH (e.g C:\MyBatches):

@echo off
set userChoice=%1
rem The format is:
rem call :condition SHORTCUT FOLDER
call :condition web c:\Git\SecThor\SecWeb\App\
call :condition cloud c:\Git\SecThor\SecCloud\dojo.backend\
call :condition good c:\Users\Vitaly\Dropbox\Projects\goodread-friends\
GOTO :eof

rem We do PUSHD twice since endlocal does popd once :|
if "%userChoice%"=="%1" pushd %2 & pushd %2 & echo pushd %2
if "%userChoice%"=="" echo %1 =^> %2
GOTO :eof

Then I can jump to any predefined folder very quickly. I wrote a full article about that technique here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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