DEV Community

Cover image for How to set permanent Aliases in Windows
Keshav Mohta
Keshav Mohta

Posted on

How to set permanent Aliases in Windows

alias are easy way to do long command short, in Unix there are .bashrc file where we can set alias but in Windows I did not find such thing straight forward, so here is the approach to do so.

approach 1

usually we can open command prompt ( win key + R ) and type cmd and set alias using doskey, for eg.

doskey ll=dir

and now when run ll it will list all files of that folder.

which works good but problem in this approach is

  1. we have to set every alias separately
  2. these alias are temporary and only for the active session, as soon as we close the command prompt, alias are gone.

approach 2

To overcome both of the above mentioned problem, following are are steps to set permanent and multiple alias

  1. first run below command in your command prompt echo %USERPROFILE% , output of above is the base path , in my case it is C:/Users/User

userprofile

  1. now create a new file name alias on above location, you can name it on your ease, even with .txt extension also

  2. now open this file in notepad or editor and add your daily use alias in it and save the file, mine are as below

cat=type $*
..=cd..
ls=dir $*
gs=git status
gp=git push
gb=git branch
nrs=npm run start
dev=cd /d D:\Developer
rct=cd /d D:\Developer\react-project
Enter fullscreen mode Exit fullscreen mode

Note:
- you need to add /d if you create an alias to navigate to any directory.
- path separator is forward slash *\ .
- there is no space around = while creating alias.

now next part is to how to make it permanent so that it is available whenever you open the command prompt.

  1. now open run win key + R and type regedit ; it will open a new dialog window which is registry editor.
  2. navigate to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor File
  3. right click to this file and select New >> String Value and rename it to Autorun and save it.

regedit dialog

  1. now double click on this newly created Autorun key, a window open where you have to put below value in value data field (the address will be full path of your alias file)
DOSKEY /MACROFILE="C:\Users\User\alias"
Enter fullscreen mode Exit fullscreen mode

value of new key

  1. close the regedit and command prompt for once.

Now try your alias and thank me later. :)

let me know if it was helpful or something incorrect while you try, I would be happy to help

Cheers.

Top comments (0)