How to set 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 (temporary)
usually we can open command prompt ( win key + R
) and type cmd and set alias using doskey
, for eg.
and now when run ll
it will list all files of that folder.
which works good but problem in this approach is
- we have to set every alias separately
- these alias are temporary and only for the active session, as soon as we close the command prompt, alias are gone.
approach 2 (permanent)
To overcome problem in approach 1, following are are steps to set permanent and multiple alias
- 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
-
now create a new file name alias on above location, you can name it anything, even with .txt extension also
-
now open this file in notepad or editor and add your daily use alias in it and save the file, mine are as below
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.
-
now open run command using Win key + R and type
regedit
it will open a new dialog window which is registry editor. -
navigate to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor File, see attached screenshot.
-
right click to this file and select New >> String Value and rename it to Autorun and save it.
-
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) . see attached screenshot
- 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.