DEV Community

pranay rauthu
pranay rauthu

Posted on • Updated on

.bashrc alternative in windows

.bashrc is a very useful file in Linux environments. It basically runs every time a new Linux shell is opened & you can add commands like aliases. I wanted to have something similar in windows. After searching over internet I have found the following technique.

  • create a .bat file with the command name in a directory. (for example if you want to use ls to list directories create a file with the name ls.bat in C:\myBatCommands with dir in it.)
  • add the folder(C:\myBatCommands) to PATH environment variable
  • you can start using the commands.

This looks simple but every time you want to add a command you need to create a new file with the name in the folder. so create a .bat file(something like cmdrc.bat) to simplify this with following content.


@echo off

set filename=%~1
set command=%~2

echo %command% > C:\myBatCommands\%filename%.bat

Enter fullscreen mode Exit fullscreen mode

Anytime you want to add a command to the folder run the following command.


#cmdrc <alias-name> <command>
cmdrc ls dir

Enter fullscreen mode Exit fullscreen mode

There are couple of other ways listed here. If there are any others ways of achieving the same please post in comments.

EDIT: 4-11-2018

If you are using powershell you can use profile.ps1 with all the aliases. for more info.

Discussion (0)