Create and Use Alias Command in Linux

How to Create and Use Alias Command in Linux

Last Updated on by ICT Byte

Linux users always or say maximum time need one command to operate the computer system. Typing same command through copying and other method can reduce your productivity and distract from what you are doing. In order to save the time you can create and use alias command in linux. Alias is the shortcut commands or say shortcut commands which executes with custom option or without it.

In this article we are going to create and use alias command in linux in order to save your few times. Without delay let’s move on the steps of Create and Use Alias Command in Linux. So, Let’s begin…

Follow the steps to list currently defined aliases in linux

You need to just type alias command in order to view the defned alias on your profile.

$ alias
Now you can see the default aliases defined for your user in Ubuntu 18.04.
Create and Use Alias Command in Linux
List Aliases in Linux OS

Here you can view the alias excuting in the dispaly.

$ ll 

Is equivalent to running:

$ ls -alF

You can Create and Use Alias Command in Linux with a single character that will be equivalent to a command of your choice.

Many people have a great misconception that It is very hard and took long process to Create and Use Alias Command in Linux. But this is not very simple, easy and fast to Create and Use Alias Command in Linux. There are two types of command in alias i.e Temporary and Parmanent. We are going to review both types commands.

Creating Temporary Aliases

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

Type the syntax is as follows:

$ alias shortName="You can type here your custom command here"

Here is an actual example:

You can then use “wr” shortcut in order to go to the webroot directory. The problem on the wr shortcut is alias is that it will only be available for your current terminal session. If you open the next triminal then the alais will no longer available. If you wish to save your aliases across the sessions then you need to create and use the aliases in linux parmanently.

Creating Permanent Aliases

In order 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"#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]

Conclusion

This is a short demo about Create and Use Alias Command in Linux and execute frequently used commands without having to type each command again and again. Now you Create and Use Alias Command in Linux which you use the most and create shortcuts for them in your shell.

We hope these guidelines help you to know How to Create and Use Alias Command in Linux. If any queries arise regarding this topic then ICT BYTE recommend you to comment below. Here, we are always active to help you so don’t hesitate to share your doubt.

Also Read:

Top 5 Open Source Video Player For Linux

Follow Us on Facebook— Trends Today

More From Author

download all photos from Google Photos

How to download all photos from Google Photos?

How to watch Friends for Free

How to watch FRIENDS for Free? 4 Easy ways to watch your favourite episodes.