Linux Command: Aliases(create command aliases or shortcuts)

We can create a shortcut or alias of any command. This is useful when we have some complex command that we use frequently, and we want an easy way to run that command, instead of copying and pasting it over and over again.

Step #1

In your home directory create a file named “.bash_aliases”.

# Create .bash_aliases file in the home directory
$ touch ~/.bash_aliases
Bash

All our aliases will be written in the “.bash_aliases” file. So open the file in your favorite text editor.

Step #2

The alias declaration in the “.bash_aliases” file will have the following format.

alias your_command_alias_name='your full command here'
alias my_custom_comm='another full command here'
Bash

After saving the file we can now execute the alias commands “your_command_alias_name” and “my_custom_comm” in the terminal. The aliases will execute the relative command written in the “.bash_aliases” file.

Note: after adding the aliases either close the terminal or start again. You can also reload the bash source using the following command.

$ source ~/.bashrc
Bash

Then the aliases will work.

Examples

For example, we have added the following lines in our “.bash_aliases” file-

alias gettime='date | cut --delimiter=" " --fields=4'
alias lsla='ls -la'
Bash

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.