Typing texts and memorizing commands is one of the downsides of being a command-line enthusiast. And if you need to type and remember the same long command, it might reduce your productivity in a terminal.

What if you can replace a long command with your own fancy short name, or group multiple commands? Yes, alias is a method that can help you use the command line efficiently.

What Is Alias In Linux? How To Use And Create Permanent Aliases?

What Does Alias Mean In Linux?

Alias is a substitute name that refers to another command or a group of commands. It helps in creating a shortcut string for commands that are long to type or memorize.

For example, if you want to sync your local directory with your remote directory, you can use the below command.

ls alias

But if you perform directory synchronization frequently, it might become tiring for you to type this long command (unless you’re using a shell with auto-suggest features).

So, to make the regular sync task easy, what you’re able to do is create an alias for rsync command.

Article image

And next time you want to transfer and sync your local content to a remote system, you can type “remote” in your terminal.

Based on the availability, alias is of two types: Temporary and Permanent. Temporary alias is available only for the current terminal session. Once you close your terminal, you can no longer use your custom aliases.

bash_aliases

On the contrary, if you create a permanent alias in Linux, you can immediately use it in a new session or even after reboot.

How To Create And Use Alias In Linux?

Alias is a command you’re able to use to create new aliases usingalias new-name=valuesyntax. No gap between name and value.

For instace, if you likeexa utilityfor listing files but still wants to uselscommand, you can make “ls” alias of “exa” and print exa output using ls command.

Once you create a bunch of aliases, you can also check or list it by simply runningaliascommand:

Later, if you want to delete or unset any of your alias, you can useunaliascommand with alias name passed as an argument.

You can also remove all aliases using-aoption to unalias command.

How To Create Permanent Aliases In Linux?

Do you want to use your aliases even after closing the terminal and rebooting to system? If yes, you need to create a permanent alias.

To do that, you need to put your alias in the~/.bashrcfile by either opening it in a editor or by running commands:

If you’re using shell other than bash, you might need to put aliases in the respective shell config file such as~/.zshrcfor ZSH and~/.config/fish/config.fishfor Fish shell.

Store Aliases In A Separate File

If you use large number of aliases, it’s always better to have a separate file for it. you’re able to create bash_aliases dot file in your home directory and put all aliases here.

Once you add alias to “bash_aliases” file, you also need to add below code in the~/.bashrcfile.