How to Set Permanent and Temporary Aliases in PowerShell and Bash: A Step-by-Step Guide
Aditya Shrivastav
Posted on June 19, 2024
Aliases are shortcuts that allow you to create custom commands to save time and improve efficiency when working in the terminal. Both PowerShell and Bash support aliasing, but the methods for setting permanent and temporary aliases differ between these shells. In this guide, we'll walk you through the steps to create and manage aliases in both PowerShell and Bash.
Setting Aliases in PowerShell
Temporary Aliases
Temporary aliases in PowerShell exist only for the duration of your current session. Once you close the terminal, these aliases will be lost.
Creating a Temporary Alias:
Open PowerShell.
-
Use the
Set-Alias
cmdlet to create your alias.
Set-Alias ll Get-ChildItem
In this example,
ll
is an alias for theGet-ChildItem
cmdlet, which is similar tols
in Unix-based systems.
Viewing Aliases:
To see a list of all aliases, use the Get-Alias
cmdlet:
Get-Alias
Permanent Aliases
To make an alias permanent, you need to add it to your PowerShell profile script. This script runs every time a new PowerShell session starts.
Creating a Permanent Alias:
Open PowerShell.
-
Open your PowerShell profile in a text editor. You can do this by running:
notepad $PROFILE
If the profile does not exist, this command will create it. You can also use your favorite text editor like VS Code or Sublime text, here I have used
notepad
for simplicity. -
Write the same command in the profile script:
Set-Alias ll Get-ChildItem
Save and close the text editor.
-
To apply the changes immediately without restarting PowerShell, run:
. $PROFILE
Setting Aliases in Bash
Temporary Aliases
Temporary aliases in Bash also exist only for the current session. They will be lost once you close the terminal.
Creating a Temporary Alias:
Open a terminal.
-
Use the
alias
command to create your alias.
alias ll='ls -la'
In this example,
ll
is an alias for thels -la
command.
Viewing Aliases:
To see a list of all aliases, use the alias
command without any arguments:
alias
Permanent Aliases
To make an alias permanent, you need to add it to your shell's configuration file, such as .bashrc
or .bash_profile
.
Creating a Permanent Alias:
Open a terminal.
-
Open your
.bashrc
file in a text editor. You can do this withnano
orvi
nano ~/.bashrc
-
Add your alias command in the
.bashrc
file:
alias ll='ls -la'
Save and close the text editor.
-
To apply the changes immediately without restarting the terminal, run:
source ~/.bashrc
Conclusion
Setting aliases in PowerShell and Bash can greatly enhance your productivity by reducing the amount of typing required for frequently used commands. Whether you need a temporary alias for a quick task or a permanent one for everyday use, the steps outlined above will help you configure your terminal to suit your workflow. Experiment with different aliases to find the ones that best fit your needs. Happy aliasing!
Posted on June 19, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024
November 30, 2024