How to Create Command Shortcuts with Aliases in Linux

How to Create Command Shortcuts with Aliases in Linux

Hello Geeky, so today we are focusing on How you can Create Command Shortcuts with Aliases in Linux. So please read this tutorial carefully so you may comprehend it in a better helpful way.

Guide: How you can Create Command Shortcuts with Aliases in Linux

Linux users frequently need to repeat the same command. Repeatedly typing or copying the same command lowers your productivity and diverts your attention away from the task at hand.

You can save time by creating aliases for your most frequently used commands. Aliases are custom shortcuts for a command (or collection of commands) that can be run with or without custom options. Aliases are likely already in use on your Linux system.

How to Create Aliases in Linux

Creating aliases is relatively easy and quick process. You can create two types of aliases – temporary ones and permanent. We will review both types.

Creating Temporary Aliases

What you need to do is type the word alias then use the name you wish to use to execute a command followed by “=” sign and quote the command you wish to alias.

The syntax is as follows:

$ alias shortName=”your custom command here”

Here is an actual example:

$ alias wr=”cd /var/www/html”

You can then use “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 new terminal session, the alias will no longer be available. If you wish to save your aliases across sessions you will need a permanent alias.

Creating Permanent Aliases

To keep aliases between sessions, you can save them in your user’s shell configuration profile file. This can be:

  • Bash – ~/.bashrc
  • ZSH – ~/.zshrc
  • Fish – ~/.config/fish/config.fish

The syntax you should use is practically the same as creating a temporary alias. The only difference comes from the fact that you will be saving it in a file this time. So for example, in bash, you can open .bashrc file with your favorite editor like this:

$ vim ~/.bashrc

Find a place in the file, where you want to keep the aliases. For example, you can add them in the end of the file. For organizations 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 loaded in 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 can be unaliased using unalias command.

$ unalias alias_name
$ unalias -a [remove all alias]

Faq

Guide about How you can Create Command Shortcuts with Aliases in Linux


In this guide, we told you about the How you can Create Command Shortcuts with Aliases in Linux; please read all steps above so that you understand How you can Create Command Shortcuts with Aliases in Linux in case if you need any assistance from us, then contact us.

How this tutorial or guide assisting you?


So in this guide, we discuss the How you can Create Command Shortcuts with Aliases in Linux, which undoubtedly benefits you.




Final note

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

Trickbugs: Get the latest Trick and Tips
Logo
Enable registration in settings - general