If you are working on Linux, you probably already know that making command line aliases is very easy to your bash console with alias
command. How about windows? This article will show you how to make easy windows command line aliases using simple Batch scripts.
Getting familiar with Path
Like on Linux we have the Path environmental variable on windows command line. Path environmental variable gives an indication to your environment on where to look for a given command.
You can change path variable while you are on the command line or on Windows PowerShell. For usual command line, you can use the following:
path=%path%;c:\AddMeToPath
Or for PowerShell:
$env:Path += ";c:\AddMeToPath"
Now whatever executable command under c:\AddMeToPath
will be available under this command line.
If you would like to add the directory to your Path permanently, you can do this easily with following command:
setx /M PATH "%path%;c:\AddMeToPath"
Note that the above command requires you to be in an elevated console (i.e. a console that run as administrator)
You can also do this graphically by going to Advanced System Settings
and finding Environmental Variables
on the Advanced
tab and appending the directory to Path variable.
Creating Aliases with Batch
First create a directory where you want your command aliases will stay such as c:\Aliases
Now go to this directory and create a new batch file hello-world.bat
as following:
@echo off
echo "Hello World!"
Now let’s try this alias without changing the Path permanently:
Enjoy your many aliases!