Be it Linux, macOS, or Windows, we sometimes need to use the terminal or the command line to perform certain commands. If in such situations, we find ourselves repeating a few long commands we can use an alias to save time and make it easier. In windows, we can create an alias as a batch command from the command prompt or the Powershell. We will see how to create and work with an alias in Batch scripting.
What is an Alias?
Alias is a shorthand command to replace another command. We can think of it as a shortcut command for multiple or long commands. It can be also understood as a map of the shortcut keyword command with the actual command. The shortcut command is replaced with the string of commands which gets executed.
Creating an Alias
To create an alias in a windows environment or a BATCH script, we can open up a CMD or Powershell instance.
The structure of an alias is as follows:
doskey parameters [shortcut command] = [commands to be executed]
A simple alias in BATCH scripting will look something like the following:
doskey cdoc = cd C:\Users\Admin\Documents
We use the keyword doskey to create an alias, the alias is simply created by specifying the shorthand command in this example the word cdoc and the final piece of information is the actual command we want to replace with this alias. Thus when we create this alias, the command cdoc executes the command cd C:\Users\Admin\Documents and hence we optimize and create a shortcut to save some time and effort.
This will create an alias for this CMD/Powershell instance only, once you exit the session or window the alias is no longer working and hence was a temporary alias.
Creating a permanent alias
To create a permanent alias, we can specify these same commands of doskey in a .bat file which is also known as the Batch script or file. After the batch script/file is created with the alias you required we can copy the path of this batch file and add it to the CMD/Powershell target to add the alias in the initialization of those environmental shells(CMD/Powershell)
Follow the steps to create a permanent alias:
Creating a batch file
We can create a simple file with any name you prefer but with a .bat extension. This batch file will contain the alias that we can use in the shells(CMD/Powershell) permanently. After creating the batch file, you can add your preferred alias in separate lines as follows:
@echo off doskey cdoc = cd C:\Users\Admin\Documents doskey ls = dir
You can add other aliases as per your requirements and desire. We have used the command @echo off so that the script doesn’t print itself while executing.
Save the file and copy the location of the file by Shift + Right-clicking the file in the windows explorer. Then select the option Copy as path and the path of the batch file will be copied in your system clipboard.
After copying the path of the file, we can move on to the next step which is to add the path to the shell program target.
Adding the batch file path to the CMD/Powershell target
- Right-click the CMD/Powershell icon and then click on the properties option.
- There you will get a window that should have multiple options, click on the shortcut tab.
- In the shortcut tab, add the character /k and paste the file location.
- And now if we restart the CMD/Powershell the alias will work and will stay permanently until we delete them from the batch file which is linked to the shell environments.
As we were able to see the thing working, the alias was loaded from the batch file which we created and linked in the CMD or Powershell’s target. This way we can keep multiple aliases in a single place or assemble multiple alias from different paths to a shell in Windows.
Replacing an Alias
To replace an alias in a batch environment, we can simply edit the shortcut name to the command we want to replace with.
doskey [shortcut command] = [new commands]
We can simply redefine the shortcut alias to the new command just as we do with variables in programming.
Note: You need to use the doskey if you are writing your aliases in the file or a batch script, but if you are creating aliases just in the CMD/Powershell instances then you don’t need to write the keyword doskey in the command.
For example, we can write the cdoc alias again as follows:
We have redefined the alias to a new command and it can now work with the latest command it was changed to.
Deleting an Alias
To disable or delete an alias is quite straightforward. We can set the shortcut alias command to empty and the Shell environment will not consider it as a valid command anymore.
doskey [shortcut command] =
Thus, we were able to delete or disable an alias in a batch script by setting the alias to an empty value.
Options/Parameters in Batch Aliases
We can use certain parameters and options in the alias to integrate certain features that can be more used to make the alias more flexible.
There are several parameters as follows:
parameter/option | description |
---|---|
/history | to get the history of the current batch environment (commands executed in CMD/ Powershell) |
/exename | to execute the macro with an executable in the system path |
/macrofile | to include a file that contains the macro to be used |
There are a lot of options and parameters we can use to enhance the alias in our batch script
Note: The entire list of options/parameters can be found in the official Microsoft docs.
We can even use command line arguments in the alias as we do with the normal batch script. This can be a really powerful tool to have especially for more complex batch tasks and scripts. Let’s say we want to create an alias that creates a folder and changes our current directory into the created folder. We can use the positional parameter specified as the folder name and create and cd into the folder.
doskey md = mkdir $1 &t cd $1
We can use the $1 to indicate the first parameter passed to the alias and $t to separate the commands in the alias.
Thus, we can now dynamically use our alias in a batch script or CMD/Powershell environment. This can be further used as per the specification of the commands.
In this article, I would like to share with you a useful way to define aliases for the command prompt. The method described in this article works in all modern Windows versions including Windows 10, Windows 8.1, Windows 8 and Windows 7. By following the steps below, you will be able to define any desired alias to extend the functionality of the default command processor (cmd.exe) and save your time.
There is a doskey command available in the command prompt. Using doskey, it is possible to define an alias for a new or existing console command.
For example, almost all users are familiar with the cd command which is used to change the current directory in the command prompt. If the desired directory is located on another drive, you need to use the «/D» switch with the cd command or enter the drive letter in the command prompt explicitly.
For example:
d: cd documents
or
cd /d d:\documents
Using DOSKEY, it is possible to save your time and define an alias which will allow you to omit the requirement to enter the drive letter and the /D switch. For example:
doskey cd=cd /D $*
The following are some special codes in Doskey macro definitions:
$T Command separator. Allows multiple commands in a macro.
$1-$9 Batch parameters. Equivalent to %1-%9 in batch programs.
$* Symbol replaced by everything following the macro name on the command line. We used it in our alias.
Now, we can compare the results without the alias and with the alias.
Without the alias, the cd command will not change the active drive:
With the alias created with DOSKEY, the command prompt will change the active drive and the current folder automatically:
This is very useful.
Using DOSKEY, it is possible to define your own aliases. For example, you can create the LS alias for the DIR command to use a common command for directory listing in Windows and Linux. As you may or may not be knowing, LS is a default file listing command in the Linux operating system.
doskey ls=dir
Or something like this:
Define global aliases in the Windows command prompt
The problem with aliases is that they work only for the command prompt instance where you have defined them. To avoid this issue, you can create a new shortcut to cmd.exe or even modify the default one. You need to add the following parameters after the cmd.exe part:
cmd.exe /k c:\apps\cmd\aliases.cmd
Here the file c:\apps\cmd\aliases.cmd is a regular batch file which contains the appropriate DOSKEY calls.
Besides the command prompt, Windows allows defining your own aliases for the Run dialog as well. Refer to the following article: Launch your favorite apps with useful aliases from the Run dialog
That’s it. This is a very useful way to define your own command or change the behavior of default commands. I am using these aliases since a very long time. What about you? Are you using aliases in the command prompt or were you not aware of this feature?
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support!
Windows CMD aliasing allows you to create shortcuts for longer commands, making them easier to use by defining your own commands with the `doskey` utility.
Here’s an example of how to create an alias:
doskey ll=dir /w /p
Understanding CMD Aliases
What is a CMD Alias?
A CMD alias is essentially a shortcut that allows you to execute commands with a simpler name or less typing effort. Think of an alias as a nickname for a command; it lets you use a shorter or more memorable term instead of the full command. For instance, instead of typing `ipconfig /all` to display your network configuration, you could create an alias that lets you just type `networkinfo`.
The primary distinction between an alias and a standard command is that aliases are customized commands made by the user, while standard commands are built into the Windows Command Prompt.
Benefits of Using Aliases
Using Windows CMD aliases comes with various advantages:
- Time-Saving Advantages: By creating a concise command for frequently used commands, you reduce the time spent typing long commands repeatedly.
- Enhanced Productivity: Short commands lead to increased efficiency, allowing you to perform tasks faster without fiddling with lengthy syntax.
- Customization: You have the freedom to define commands that suit your workflow, tailoring them to your everyday tasks.
Windows Cmd Clear: Refresh Your Command Line Effortlessly
Creating CMD Aliases
How to Create an Alias in Windows CMD
Creating an alias in Windows CMD can be done easily using the `doskey` command. Here’s a straightforward process on how to do that:
- Open Command Prompt.
- Use the `doskey` command to create an alias. The basic syntax is:
doskey aliasName=command
For example, to create an alias that lists directory contents, you can do:
doskey ls=dir
Now whenever you type `ls`, it will run the `dir` command.
Permanent vs Temporary Aliases
Defining Temporary Aliases
Temporary aliases exist only for the duration of the Command Prompt session. They are removed once you close the CMD window. To create a temporary alias, follow the steps mentioned previously. For example:
doskey cls=clear
This alias will work fine during that session but will be lost once you close CMD.
Defining Permanent Aliases
In contrast, a permanent alias remains stored even after you close CMD. To create permanent aliases, you need to set them up in your CMD configuration using `doskey`. Here’s how:
- Open a Command Prompt and type:
doskey /macrofile=yourAliasFile.txt
- In `yourAliasFile.txt`, you can define your aliases in the same way:
ls=dir
cls=clear
Every time you open CMD, simply run the above command to load your macro file, and your aliases will be ready for use.
Mastering Windows Cmd Disk Management in Minutes
Managing Aliases
Listing Existing Aliases
To see all the aliases currently available, you can list them by executing:
doskey /macros
This command will display all the active aliases, helping you keep track of what you have created.
Editing Aliases
If there is a need to modify an alias, you can simply redefine it using the `doskey` command. For instance, if you want to update the `ls` alias to include a specific option like detailed view, you can do:
doskey ls=dir /w
Deleting Aliases
To remove an alias you no longer need, use the `doskey /delete` command followed by the alias name:
doskey /delete ls
This command will remove the `ls` alias from your current CMD session.
Mastering Windows Cmd Arp for Networking Success
Advanced CMD Alias Features
Using Parameters in Aliases
Creating aliases that accept parameters can make your commands more flexible. For example, if you want to create an alias that opens a specific FTP server, you can do:
doskey ftp=start ftp $*
Here, typing `ftp myserver` will execute `start ftp myserver`, allowing for dynamic usage based on user input.
Using Batch Files with Aliases
You can also create batch files and use them as aliases for commands that require multiple steps. For instance, if you have a batch file named `runpython.bat`, you can define an alias for it:
doskey runpython=python C:\scripts\script.py
Now, typing `runpython` in the command line will execute the specified Python script.
Unlocking The Power Of Windows Cmd Whois
Troubleshooting Common Alias Issues
Common Problems with Aliases
As with any feature, users may encounter common issues when using Windows CMD aliases. Some include conflicts with existing commands or aliases not working as expected.
One solution is to ensure that your alias names do not conflict with existing CMD commands or reserved keywords.
Checking Compatibility
Not all versions of Windows support CMD aliases in the same way. Ensure that you are using a compatible version of Windows. If you experience issues, confirm whether your Windows version has limitations related to CMD features.
Windows Cmd Repair: Quick Fixes You Need to Know
Best Practices for Creating and Managing Aliases
To maximize the benefits of CMD aliases:
- Effective Naming Conventions: Keep your alias names intuitive and descriptive to minimize confusion.
- Organization: Group similar aliases together within a file if utilizing them in bulk.
- Documentation: Maintain a list of your aliases and their functions, updating them as necessary.
This practice will not only help you remember what each alias does but also assist others if they need to use your system.
Mastering Windows Cmd Switches: A Concise Guide
Conclusion
In summary, using Windows CMD aliases can significantly enhance your command-line efficiency. They streamline repetitive tasks, increase productivity, and allow for tailored experiences in your command-line interactions. Embrace the power of aliases and start customizing your CMD environment today.
Mastering Windows Cmd Version: Essential Tips and Tricks
Call to Action
What are some of your favorite CMD aliases? Share them with us! Also, consider signing up for our newsletter to receive more tips and tricks related to Windows CMD usage.
- Alias Command
- How to set aliases for the command prompt in Windows
- Add alias
- Using Aliases
- Aliases in Windows command prompt
- Console Aliases
- Using aliases
Alias Command
This example creates a new alias, upper, for the complete command
Edit.MakeUpperCase. cmd. >Tools.Alias upper Edit.MakeUpperCase. This example
deletes …
Tools.Alias [/delete] [/reset] [aliasname] [aliasstring]
>Tools.Alias upper Edit.MakeUpperCase
>Tools.alias /delete upper
>Tools.Alias
How to set aliases for the command prompt in Windows
You need to add the following parameters after the cmd.exe part: cmd.exe /k
c:\apps\cmd\aliases.cmd. Here the file c:\apps\cmd\aliases.cmd is a regular
batch file which …
d:
cd documents
cd /d d:\documents
doskey cd=cd /D $*
doskey ls=dir
cmd.exe /k c:\apps\cmd\aliases.cmd
Add alias
Adds aliases to the alias environment. If used without parameters, add alias
displays help at the command prompt. Aliases are saved in the metadata file
and will be …
add alias <aliasname> <aliasvalue>
list shadows all
* Shadow Copy ID = {ff47165a-1946-4a0c-b7f4-80f46a309278}
%VSS_SHADOW_1%
add alias System1 %VSS_SHADOW_1%
add alias System1 {ff47165a-1946-4a0c-b7f4-80f46a309278}
Using Aliases
In this article. Aliases are character strings that are automatically replaced
with other character strings. You can use them in debugger commands and to
avoid retyping …
.foreach (value {dd 610000 L4})
{
as /x ${/v:myAlias} value + 1
.echo value myAlias
}
ad myAlias
0:001> $$>< c:\Script02.txt
00610000 myAlias
00905a4d 0x610001
00000003 0x905a4e
00000004 0x4
0000ffff 0x5
.foreach (value {dd 610000 L4})
{
as /x ${/v:myAlias} value + 1
.block{.echo value myAlias}
}
ad myAlias
0:001> $$>< c:\Script01.txt
00610000 0x610001
00905a4d 0x905a4e
00000003 0x4
00000004 0x5
0000ffff 0x10000
r $t0 = 5
ad myAlias
.foreach /pS 2 /ps 2 (Token {[email protected]$t0}) {as myAlias Token}
al
Alias Value
------- -------
myAlias Token
r $t0 = 5
ad myAlias
.foreach /pS 2 /ps 2 (Token {[email protected]$t0}) {;as myAlias Token}
al
Alias Value
------- -------
myAlias 5
0:000> r $.u2=2
0:000> r $.u1=1+$u2
0:000> r $.u2=6
0:000> ? $u1
Evaluate expression: 3 = 00000003
0:000> as fred 2
0:000> r $.u1= 1 + fred
0:000> as fred 6
0:000> ? $u1
Evaluate expression: 3 = 00000003
0:000> r $.u0=2
0:000> r $.u0=7+$u0
0:000> ? $u0
Evaluate expression: 9 = 00000009
0:000> as Short usersrv!NameTooLongToWantToType
0:000> dw Short +8
0:000> r $.u0=usersrv!NameTooLongToWantToType
0:000> dw $u0+8
0:000> as GoUp r eax=eax+1; r ebx=ebx+1
0:000> GoUp
0:000> GoUp
0:000> as Cmd "dd esp 14; g"
0:000> bp MyApi Cmd
0:000> r $.u5="dd esp 14; g"
0:000> bp MyApi $u5
0:000> bp MyApi "dd esp 14; g"
[NTSD]
$u1:_ntdll!_RtlRaiseException
$u2:"dd esp 14;g"
$u9:$u1 + 42
Aliases in Windows command prompt
565. To add to josh’s answer, you may make the alias (es) persistent with the
following steps, Create a .bat or .cmd file with your DOSKEY commands. Run
regedit and go to …
@echo off
:: Temporary system path at cmd startup
set PATH=%PATH%;"C:\Program Files\Sublime Text 2\"
:: Add to path by command
DOSKEY add_python26=set PATH=%PATH%;"C:\Python26\"
DOSKEY add_python33=set PATH=%PATH%;"C:\Python33\"
:: Commands
DOSKEY ls=dir /B $*
DOSKEY sublime=sublime_text $*
::sublime_text.exe is name of the executable. By adding a temporary entry to system path, we don't have to write the whole directory anymore.
DOSKEY gsp="C:\Program Files (x86)\Sketchpad5\GSP505en.exe"
DOSKEY alias=notepad %USERPROFILE%\Dropbox\alias.cmd
:: Common directories
DOSKEY dropbox=cd "%USERPROFILE%\Dropbox\$*"
DOSKEY research=cd %USERPROFILE%\Dropbox\Research\
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%USERPROFILE%\\alias.cmd"
@ECHO OFF
REM Add other configurations as needed
IF EXIST "%USERPROFILE%\alias.cmd" ( CALL "%USERPROFILE%\alias.cmd" )
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="C:\\Users\\Public\\init.cmd"
doskey np=notepad++.exe $*
cmd.exe /K env.cmd
title "Foo Bar"
doskey np=notepad++.exe $*
...
@echo off
echo.
dig +noall +answer %1
@echo off
echo.
notepad++.exe %1
@echo off
echo.
notepad++.exe %*
np c:\temp\abc.txt c:\temp\def.txt c:\temp\ghi.txt
alias subl="C:\Program Files\Sublime Text 3\subl.exe" $*
@echo off
call notepad++.exe %*
@echo %2 %3 %4 %5 %6 > %windir%\%1.cmd
alias nameOfYourAlias commands to run
nameOfYourAlias
commands to run
setx PATH "%PATH%;%ProgramFiles%\Sublime Text 3" /M
subl index.html
doskey test=cd \a_very_long_path\test
AddConsoleAlias( TEXT("test"),
TEXT("cd \\<a_very_long_path>\\test"),
TEXT("cmd.exe"));
c:\>alias kgs kubectl get svc
Created alias for kgs=kubectl get svc
c:\>kgs alfresco-svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alfresco-svc ClusterIP 10.7.249.219 <none> 80/TCP 8d
@echo off
echo.
for /f "tokens=1,* delims= " %%a in ("%*") do set ALL_BUT_FIRST=%%b
echo @echo off > C:\Development\alias-script\%1.bat
echo echo. >> C:\Development\alias-script\%1.bat
echo %ALL_BUT_FIRST% %%* >> C:\Development\alias-script\%1.bat
echo Created alias for %1=%ALL_BUT_FIRST%
@echo off
echo.
kubectl get svc %*
@echo off
if [%1]==[] goto nofiles
start "" "c:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\devenv.exe" /edit %1
goto end
:nofiles
start "" "C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\devenv.exe" "[PATH TO MY NORMAL SLN]"
:end
alias vs='/usr/bin/run_visual_studio.sh'
#!/bin/bash
cmd.exe /C 'c:\Windows\System32\vs.cmd' "`wslpath.sh -w -r $1`"
vs SomeFile.txt
;==============================================================================
;= This file is registered via registry to auto load with each instance of cmd.
;================================ general info ================================
;= https://stackoverflow.com/a/59978163/985454 - how to set it up?
;= https://gist.github.com/postcog/5c8c13f7f66330b493b8 - example doskey macrofile
;========================= loading with cmd shortcut ==========================
;= create a shortcut with the following target :
;= %comspec% /k "(doskey /macrofile=%userprofile%\cmd\aliases.mac)"
alias=subl %USERPROFILE%\cmd\aliases.mac
hosts=runas /noprofile /savecred /user:QWERTY-XPS9370\administrator "subl C:\Windows\System32\drivers\etc\hosts" > NUL
[email protected] "~~ powercfg -devicequery wake_armed ~~" && powercfg -devicequery wake_armed && @echo "~~ powercfg -requests ~~ " && powercfg -requests && @echo "~~ powercfg -waketimers ~~"p && powercfg -waketimers
ls=ls --color=auto $*
ll=ls -l --color=auto $*
la=ls -la --color=auto $*
grep=grep --color $*
~=cd %USERPROFILE%
cdr=cd C:\repos
cde=cd C:\repos\esquire
cdd=cd C:\repos\dixons
cds=cd C:\repos\stekkie
cdu=cd C:\repos\uplus
cduo=cd C:\repos\uplus\oxbridge-fe
cdus=cd C:\repos\uplus\stratus
npx=npx --no-install $*
npxi=npx $*
npr=npm run $*
now=vercel $*
;=only in bash
;=alias whereget='_whereget() { A=$1; B=$2; shift 2; eval \"$(where $B | head -$A | tail -1)\" [email protected]; }; _whereget'
history=doskey /history
;= h [SHOW | SAVE | TSAVE ]
h=IF ".$*." == ".." (echo "usage: h [ SHOW | SAVE | TSAVE ]" && doskey/history) ELSE (IF /I "$1" == "SAVE" (doskey/history $g$g %USERPROFILE%\cmd\history.log & ECHO Command history saved) ELSE (IF /I "$1" == "TSAVE" (echo **** %date% %time% **** >> %USERPROFILE%\cmd\history.log & doskey/history $g$g %USERPROFILE%\cmd\history.log & ECHO Command history saved) ELSE (IF /I "$1" == "SHOW" (type %USERPROFILE%\cmd\history.log) ELSE (doskey/history))))
loghistory=doskey /history >> %USERPROFILE%\cmd\history.log
;=exit=echo **** %date% %time% **** >> %USERPROFILE%\cmd\history.log & doskey/history $g$g %USERPROFILE%\cmd\history.log & ECHO Command history saved, exiting & timeout 1 & exit $*
exit=echo **** %date% %time% **** >> %USERPROFILE%\cmd\history.log & doskey/history $g$g %USERPROFILE%\cmd\history.log & exit $*
;============================= :end ============================
;= rem ******************************************************************
;= rem * EOF - Don't remove the following line. It clears out the ';'
;= rem * macro. We're using it because there is no support for comments
;= rem * in a DOSKEY macro file.
;= rem ******************************************************************
;=
Autorun REG_SZ doskey /macrofile=%userprofile%\cmd\aliases.mac
Autorun_ REG_SZ %USERPROFILE%\cmd\cmdrc.cmd
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"Autorun"="doskey /macrofile=%userprofile%\\cmd\\aliases.mac"
"Autorun_"="%USERPROFILE%\\cmd\\cmdrc.cmd"
:: This file is registered via registry to auto load with each instance of cmd.
:: https://stackoverflow.com/a/59978163/985454
@echo off
doskey /macrofile=%userprofile%\cmd\aliases.mac
:: put other commands here
cd /D D:\Folder
g++ -o run whatever.cpp
@echo off
notepad++.exe
@echo off
if not exist aliases goto:eof
echo [Loading aliases...]
for /f "tokens=1* delims=^=" %%i in (aliases) do (
echo %%i ^<^=^> %%j
doskey %%i=%%j
)
doskey aliases=doskey /macros
echo --------------------
echo aliases ^=^> list all
echo alt+F10 ^=^> clear all
echo [Done]
alias1 = command1
alias2 = command2
...
b = nmake
c = nmake clean
r = nmake rebuild
com=D:\website_development\laragon\bin\php\php-8.1.2-Win32-vs16-x64/php8 D:\website_development\laragon\bin\composer/composer.phar
@echo off
set path=D:\website_development\laragon\bin\php\php-8.1.2-Win32-vs16-x64/php8 D:\website_development\laragon\bin\composer/composer.phar
set args=%*
set command=%path% %args%
%command%
@ECHO OFF
doskey dl=aria2c --file-allocation=none $*
aria2c --file-allocation=none %**
Console Aliases
When you type «test» at the command line, the console subsystem expands the
alias and executes the specified cd command. To define a console alias, use
Doskey.exe to …
AddConsoleAlias( TEXT("test"),
TEXT("cd \\<a_very_long_path>\\test"),
TEXT("cmd.exe"));
Using aliases
An alias is an alternate name or shorthand name for a cmdlet or for a command
element, such as a function, script, file, or executable file. You can run the
command using …
Get-Command -Noun Alias
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Export-Alias 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Get-Alias 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Import-Alias 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet New-Alias 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Remove-Alias 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Set-Alias 7.0.0.0 Microsoft.PowerShell.Utility
Get-Alias -Definition Get-ChildItem
CommandType Name
----------- ----
Alias dir -> Get-ChildItem
Alias gci -> Get-ChildItem
Alias ls -> Get-ChildItem
Get-Alias -Name gci
CommandType Name
----------- ----
Alias gci -> Get-ChildItem
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
Enter fullscreen mode
Exit fullscreen mode
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"
Enter fullscreen mode
Exit fullscreen mode
- 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.