Linux users often require repeated use of a command. Type or copy over and over again the same command will reduce your productivity, and distract your hands.
You can save some time by creating aliases for the most commonly used commands. Alias as a custom shortcut for representing use or non-use customization options execution of the command (or command set). You may have used an alias on the Linux system.
It lists the currently defined aliases Linux
Just execute the alias command, you can see a list of defined aliases in the configuration file.
As you can see, execution.
$ ll
The equivalent of running:
ls -l --color=auto
You can create an alias using a single character, the alias will be equivalent to the command of your choice.
How to create an alias in Linux
Create an alias is relatively easy and fast. You can create two types of aliases - alias temporary and permanent aliases. We will review both types.
Create a temporary alias
You need to do is type the word alias, and then use the name that you want to execute the command, followed by "=" sign and the command you want to reference the alias.
The syntax is as follows:
$ Alias abbreviation = 'Your custom command here'
This is a practical example:
$ alias idc='cd /home/www/share'
You can then use the "idc" shortcut to / home / www / share directory. The alias problem is that it only applies to your current terminal session.
If you open a new terminal session, alias no longer available. If you want to save the alias across sessions, you will need a permanent alias.
Create permanent aliases
To retain the alias between sessions, they can be stored in the user's shell configuration file. This can be:
- Bash – ~/.bashrc
- ZSH – ~/.zshrc
- Fish – ~/.config/fish/config.fish
You should use the syntax is almost identical to creating a temporary alias. The only difference from the time you save it in a file. For example, in bash, you can use your favorite editor to open the .bashrc file as follows:
$ vim ~/.bashrc
Find the location you want to keep the alias in the file. For example, you can add them to the end of the file. For organizational purposes, you can leave a comment before an alias, as follows:
# My custom alias
alias home = "ssh -i ~ / .ssh / mykep.pem [email protected]"
save document. The file will automatically load your next session. If you want to use an alias newly defined in the current session, issue the following command:
$ source ~/.bashrc
To delete an alias line to add a command, you can use the alias command to cancel unalias.
Unalias alias_name $
$ unalias -a [Delete all aliases]
to sum up
This is a brief example of how to create your own alias and execute common commands, without having to type each command again and again. Now you can consider the most commonly used commands, and create shortcuts for them in the shell.