Linux users may often need to use the same command over and over again, and repeatedly typing or copying the same command can greatly reduce productivity. To reduce this situation, you can save space by using the most common common aliases for common commands. Aliases can be understood as custom shortcuts, representing commands (or sets of commands) that can be executed with or without custom options, although you may already be using aliases on Linux without even realizing it.
You can view the list of defined aliases on your profile simply by executing the alias command:
$ alias
The output will have the default alias defined by the user in Ubuntu. Running the ll command is equivalent to running the ls-alF command.
$ ll
$ ls -alF
You can also create an alias with a single character that acts as the selected command. Creating an alias is also a very simple process, and you can create two types of aliases, temporary and permanent. To create a temporary alias in Linux, simply type the word alias, use the name of the command you want to execute, and then "=" sign and reference the command you want to alias.
$alias shortName=" Enter your custom command here"
Actual case:
$ alias wr=”cd /var/www/html”
When you're done, you can use the wr shortcut to go to the webroot directory. The problem with this alias is that it only applies to the current terminal session. This temporary alias is invalidated when a new terminal session is opened. If you want the alias to be permanently available, simply save it in the user's shell profile:
Bash – ~/.bashrc
ZSH – ~/.zshrc
Fish – ~/.config/fish/config.fish
The syntax used is the same as for creating a temporary alias, the only difference is that this time you save it in a file, as in bash using the editor to open the.bashrc file, as shown below:
$ vim ~/.bashrc
Find the location in the file where you want to save the aliases, such as adding them at the end of the file, and leave a comment before the aliases for organizational purposes such as:
#My custom aliasesalias home= "ssh -i ~/.ssh/mykep.pem tecmint@192.168.0.100" alias ll=" ls-alF"
If you save it, the file will be automatically loaded in the next session. If you use the newly defined alias in the current session, use the following command:
$ source ~/.bashrc
To remove aliases that are added from the command line, you can cancel aliases using the unalias command:
$ unalias alias_name
$ unalias -a [remove all alias]
This is a simple example of creating your own alias and executing a common command that eliminates the need to type the command over and over again. Consider creating shell shortcuts to frequently used commands.