How to create an alias in Linux
Using an alias in Linux to create a custom command or sequence of commands.
2
Introduction
In Linux, an alias is a shortcut for a command or a sequence of commands. It allows users to create custom, easy-to-remember names for frequently used or complex commands, making workflows more efficient and reducing typing errors.
Create Your First Alias!
- Open the terminal and type the following command:
sudo nano ~/.bashrc
- Create a heading introducing your custom alias following the example below:
# Custom aliases
alias aliasedit='sudo nano ~/.bashrc'
This above alias will allow you to edit your
.bashrc
file.
-
Save and exit the file by pressing
Ctrl + X
, thenY
, and thenEnter
. -
To use your alias, simply type the name of the alias followed by the
Enter
key.
aliasedit
Aliases That I Use Daily
· To Home Directory
alias home='cd $HOME'
· To the Desktop
alias desktop='cd ~/Desktop'
· To Install Packages
alias inst='sudo apt install'
· To Perform a Soft Reset of the Last Commit
alias gitsoft='git reset --soft HEAD~1'
· To Perform a Hard Reset of the Last Commit
alias githard='git reset --hard HEAD~1'