create bash aliases

Create Bash Aliases In Linux Operating System [ Beginner’s Guide]

Insight: Create Bash Aliases In Linux Operating System [ Beginner’s Guide]

It is tedious and boring to type a long command every-time or even more boring to search the history of typed command in the terminal. There is an easy solution for this and the solution is Bash Aliases.

You can set a shortcut command for the long command which you might need to execute regularly. In this tutorial we are going to show you the method to create bash aliases in Linux. We are trying to simplify this process.

Create Bash Aliases In Linux Operating System

Syntax is as follows:

alias_name="command"

Generally, You can create bash aliases for the current session or permanently until you delete it. You can easily create a temporary bash alias by typing alias keyword.

For example:
alias omg="cd /home/omgfoss/public_html"

Above command will create a simple bash alias named omg which will be a shortcut command for the cd /home/omgfoss/public_html command or process. What you have to remember is that this alias only last for the current shell session only.

If you want to create a bash alias for the long term then you need to declare it in the ~/.bash_profile or ~/.bashrc file. Let’s create a bash alias in the .bashrc file.

At first you need to open the~/.bashrc in your text editor:

 

alias turnoff='ifdown eth0'
alias omg='cd /home/omgfoss/public_html'

 

There is no limitation in number of bash aliases that you can create in this file. Once done, You need to save and close the bashrc file.  Run the following command to make it available in current session.

source ~/.bash_profile

 

Let us know if there is any error in this tutorial post.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *