Linux users often need to use a command over and over again. Typing or copying the same command over and over again reduces your productivity and distracts you from what you’re actually doing.
You can save yourself some time by creating aliases for your most commonly used commands. Aliases are like custom shortcuts used to represent a command (or set of commands) executed with or without custom options. Most likely, you are already using aliases on your Linux system.
List of currently defined aliases in Linux You can view a list of aliases defined in your
profile by simply running the alias command
. $ alias Here you can see
the default aliases defined for your user in Ubuntu 18.04.
<img src="https://www.tecmint.com/wp-content/uploads/2018/10/List-Aliases-in-Linux.png" alt="List
As you can see, running
. $ ll
It is equivalent to executing:
$ ls -alF You can create an alias
with a single character that will be equivalent to a command of your choice
How to create aliases in Linux Creating aliases is
a relatively easy and quick process. You can create two types of aliases: temporary and permanent. We will review both types.
temporary aliases What you need to do is type the word alias and then use the name you want to
use to execute a command followed by the “=” sign and cite the command you want alias.
The syntax is as follows
: $ alias shortName=”your custom command here”
Here is a real example:
$ alias wr=”cd /var/www/html”
You can then use the “wr” shortcut to go to the webroot directory. The problem with that alias is that it will only be available for your current terminal session.
If you open a new terminal session, the alias will no longer be available. If you want to save your aliases in all sessions, you will need a permanent alias.
To maintain aliases between sessions, you can save them to the user’s shell configuration profile file. This can be:
Bash – ~/.bashrc ZSH – ~/.
- zshrc Fish – ~
The syntax you should use is pretty much the same as creating a temporary alias. The only difference comes from the fact that this time you will save it to a file. So, for example, in bash, you can open the .bashrc file with your favorite editor like this: $vim ~ / . Bashrc
Find a place in the file where you want to save the aliases. For example, you can add them to the end of the file. For organizational purposes, you can leave a comment before your aliases something like this: #My custom aliases
alias home=”ssh –i ~/.ssh/mykep.pem [email protected]” alias ll=”ls -alF”
Save the file. The file will be uploaded automatically in the next session. If you want to use the newly defined alias in the current session, run the following command:
$ source ~/.bashrc To remove an alias
added through the command line, you can override
the alias using the unalias command. $ unalias alias_name $ unalias -a [remove all aliases]
This was a brief example of how to create your own alias and execute frequently used commands without having to type each command over and over again. Now you can think of the commands you use the most and create shortcuts for them in your shell.