How to Create Command Shortcuts with Aliases in Linux – Guide

Linux users often need to repeat the same command. Repeatedly typing or copying the same command decreases your productivity and distracts you from the task at hand. You can save time by creating aliases for frequently used commands. Aliases are custom shortcuts to a command (or collection of commands) that can be run with or without custom options. Most likely, aliases are already in use on your Linux system.

How to Create aliases on Linux

Creating aliases is a relatively easy and quick process. You can create two types of aliases – temporary and permanent. Let’s review both types.

Creating temporary nicknames

What you need to do is type the word nickname and then use the name you want to use to execute a command followed by the “=” sign and quote the command you want to create the nickname for. 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 this alias is that it will only be available to 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 between sessions, you will need a permanent alias.

Creating Permanent Aliases

To keep aliases between sessions, you can save them in the user’s shell configuration profile file. This can be: The syntax you should use is pretty much the same as creating a temporary alias. The only difference comes from the fact that you will be saving it to a file this time. For example, in bash, you can open the .bashrc file with your favorite editor like this: $vim ~ / .bashrc Find a location in the file where you want to keep the nicknames. For example, you can add them to final 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 tecmint@192.168.0.100” alias ll = “ls -alF”

Save the file. The file will be automatically uploaded on your next session. If you want to use the newly defined alias in the current session, issue the following command: $ source ~ / .bashrc To remove an alias added via the command line, you can disable the alias using the unalias command. $ unalias alias_name $ unalias -a [remove all alias]

Final note

I hope you like the guide How to Create Command Shortcuts with Aliases in Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.

How to Create Command Shortcuts with Aliases in Linux  2022  - 51How to Create Command Shortcuts with Aliases in Linux  2022  - 54How to Create Command Shortcuts with Aliases in Linux  2022  - 54How to Create Command Shortcuts with Aliases in Linux  2022  - 12