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
- 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
To overcome both of the above mentioned problem, 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 on your ease, 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
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
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 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
- 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)
DOSKEY /MACROFILE="C:\Users\User\alias"
- 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)