doskey in Windows is just like alias in Linux

doskey in Windows is just like alias in Linux

Category : How-to

Get Social!

doskey on Windows is very similar to alias on Linux, it allows you to set a term which will call a command and allow you to specify default arguments. You can specify that the command showdirs could call the command dir to list the content of a folder.

You may have guessed, the above use of doskey is unlikely and has no real benefit. A better use of the command would be to turn some of the windows commands into their Linux counterparts – such as ls into dir.

Run the below command in a command prompt to alias ls to run the command dir. The $* on the end are required so that any additional arguments are also passed to the dir command.

The problem with this is that all of your alias commands will be lost when you close the cmd session. To make them persist we need to create a batch file and add the entry to the windows registry.

Create a new folder in the windows directory called bin and create a new batch file inside it.

Add your entries to the batch file in the below format.

Next, open up regedit.exe and add an entry to the batch file to make the doskey commands permanent for each cmd session.

Add a new String Value called AutoRun and set the absolute path in the value of c:\windows\bin\doskey.bat.

The doskey.bat file will now be executed before opening a new cmd session which will set all of your alias ready for you to use.

 


Related posts:


12 Comments

Solaman Huq

28-Jan-2015 at 7:15 pm

This doesn’t seem to work with only one “doskey”…for me, “doskey” must be included per line. I am running Windows 8.1 btw

    james.coyle

    28-Jan-2015 at 11:11 pm

    I have not tried this on Windows 8.

    F

    27-Feb-2015 at 9:23 am

    of course there are missing DOSKEY :) it should be:
    @echo off
    @doskey ls=dir $*
    @DOSKEY mv=move $*
    @DOSKEY cp=copy $*
    @DOSKEY cat=type $*

      james.coyle

      27-Feb-2015 at 9:44 am

      Thanks, post updated. :)

Nick Haakman

13-Aug-2015 at 1:49 pm

Has anyone got this to work in windows 8.1 yet?

    Ed Meyer

    9-Jan-2016 at 4:49 pm

    Yes. I had commented previously that I couldn’t get it to work in Windows 8.1, but I have since succeeded. I’d be happy to share with anyone still interested.

Renate

5-Dec-2015 at 9:34 pm

Nice! (Although after “@echo off” you don’t @ on the other lines.)

Ed Meyer

8-Jan-2016 at 9:13 am

I cannot get this to work on my windows 8.1 Dell laptop. The doskey definition works fine alone, but I cannot save it following the instructions given. I believe I have done everything stated in this article. I entered AutoRun=c:\windows\bin\doskey.bat into the registry, but the key I defined with doskey in the batch file is not recognized. What am I missing?

Dan J.

11-Apr-2016 at 11:19 am

I’m not sure if things have changed since this was written or if the author was simply unaware of the way cmder works but the above isn’t necessary. If you check cmder settings/Startup, {cmd} is started with this command line:

cmd /k “%ConEmuDir%\..\init.bat” -new_console:d:%USERPROFILE%

init.bat, in turn, contains this:

:: Add aliases
@doskey /macrofile=”%CMDER_ROOT%\config\aliases”

For my system (Windows 7), that directory is:

C:\Program Files (x86)\cmder\config

If you’re using a different version of Windows, it may be something else, not sure but should be straightforward to track down. Just run

cd “%CMDER_ROOT%\config\”

Add whatever aliases you like to the alias file.

    james.coyle

    11-Apr-2016 at 11:26 am

    Hi Dan – I’m not sure how that helps – nobody here has mentioned Cmder. Thats another application that would need to be installed to get the functionality you require. If that was what the post was about, I’d have mentioned Cygwin as converting Windows commands to Linux commands is the biggest use I have for doskey.

Cris

6-Jun-2018 at 7:55 am

Thank you! Very good explanation!

John

8-Sep-2018 at 11:43 am

Is there a way to get this alias mechanism to work in a pileline? For example, I would like to be able to:

tasklist | grep tasklist

where grep is somehow aliased to ‘findstr’?

Leave a Reply

Visit our advertisers

Search

Quick Poll

How often do you change the password for the computer(s) you use?

Visit our advertisers