Security

How to add Command Alias Name In Linux

Hi All !

Today we are going to see about command alias in Linux. You can create command alias for often used lengthy command to save your time.

Syntax :

Alias short cut name = ‘Customer command’.

Ex : alias ll = ‘ls -l’.

You may seen the “ll” command to list files/directory which is alias name of “ls -l”.

Methods :
There are two methods for adding alias name that is

  1. Temporary Alias
  2. Permanent Alias

Temporary Alias :

Temporary alias names are created via alias command in user’s terminal. Like

root@vps ~]# alias ll='ls -l'
[root@vps ~]#

On above alias is command, ll is alias name & ‘ls -l’ custom command.

These command will be removed once server rebooted since those temporary alias.

Permanent Alias :

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:

root@vps ~]# vi ~/.bashrc

ind 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:

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

Save the file. The file will be automatically loaded in your next session

To remove an alias added via the command line can be unaliased using unalias command.

[root@vps ~]# unalias alias_name

Hope this will be helpful πŸ™‚

Leave a Reply

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