Persisting aliases in Windows
Nov 2012
The doskey command (cmd.exe) and alias command (bash) don’t persist between sessions. bash gives us a config file we can save the commands to for persistence but cmd has no such file.
Persisting doskey (cmd)
For cmd the quickest fix is to script this to run during the initialisation of cmd.exe.
- Create the script aliases_initialise.cmd in your directory_of_choice (i.e. c:\directory_of_choice\aliases_initialise.cmd) and enter your aliases
@echo off
cls
doskey clear=cls
doskey ls=dir
- Run the command
reg add "hkcu\software\microsoft\command processor" /v Autorun /t reg_sz /d c:\directory_of_choice\aliases_initialise.cmd
Persisting alias (bash)
- Create a .bashrc file under ~/.bashrc (~ is usually /c/Users/
)
$ notepad ~/.bashrc
- Add your aliases to the file, save and restart the session.
alias ..='cd ..'
alias ...='cd ../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'