Adding an alias in Windows 7 or making ls = dir in a command prompt
I don’t know about you but I switch between FreeBSD and Windows a lot. So it drives me crazy when I type the command ls on windows and get the error message.
So I want this to go away.
I looked for the alias command in Windows and couldn’t find one. So I made a batch file that solves this.
Windows doesn’t seem to have the equivalent of a .shrc or .cshrc or .bashrc. I couldn’t find a .profile either. So I decided to go with the batch file route.
Creating a batch file as an alias
I created an
Here is how it works.
Create a file called ls.bat. Add the following text.
Copy this batch file to your C:\Windows\System32 directory. Now you can type in ls on a windows box at the command prompt and it works.
How does this work to make your aliased command?
- Name the batch file the name of the alias. I want to alias ls to dir, so my batch file is named ls.bat.
- In the batch file, set the RealCMDPath variable to the proper value, in my case it is dir.
So if you want to alias cp to copy, you do this:
- Copy the file and name it cp.bat.
- Edit the file and set this line:
Now you have an alias for both ls and cp.
Using different versions of msbuild.exe
You can also use this so you don’t have to add a path.
I need to use C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe but sometimes I want to use C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe. Both files are named the same. So I can easily use my alias command.
- Create two files in C:\Windows\System32: one named msbuild35.bat and one named msbuild40.bat.
- Change the line in each file to have the appropriate paths for the RealCMDPath.
Anyway, this is really a useful batch file.