Linux Shell alias Command

Linux administrators and most of linux users use some commands very frequently in CLI. Shortcut commands like alias is very useful for linux admins and users. You can create shortcuts for frequently used commands by adding aliases into the bash configuration file (/etc/bash.bashrc or ~/.bashrc). The syntax of this command will be as follows:

alias shortcut-command=”regular-command”

List of all defined aliases commands, type following command and enter:

alias

Sample output:

alias egrep=’egrep –color=auto’
alias fgrep=’fgrep –color=auto’
alias grep=’grep –color=auto’
alias l=’ls -CF’
alias la=’ls -A’
alias ll=’ls -alF’
alias ls=’ls –color=auto’

1. Create an Alias

For example, we create the alias “edit” for the commonly used “vim” command, which edit or open the file. We will just type following command:

alias edit=’vim’

Here, we can use more aliases and after that you will use just shortcuts commands as shown below:

alias c=’clear’
alias ports=’netstat -tulanp’
alias update=’yum update’
alias ping=’ping -c 5′
alias df=’df -H’
alias du=’du -ch’
alias jobs=”ps aux”
alias ls=’ls –color’

Then, we just write edit instead of typing vim, you would see that editor will open.

edit
c
ports
update
ping
df
du
ps
ls

For people who are familiar to MS-DOS commands, the following aliases can be defined so that we can use like MS-DOS commands in linux operating systems.

alias dir=”ls”
alias copy=”cp”
alias rename=”mv”
alias md=”mkdir”
alias rd=”rmdir”
alias del=”rm -i”

2. Disable an Alias Temporarily

Using the following syntax we can disable an alias temporarily:

## call alias with a backslash ##
\ls

OR

“ls”

Or just use the full path:

## path/to/full/command ##

$(which ls)
/bin/ls

3. Remove an Alias Permanently

To remove aliases you will go through the command called ‘unalias’. Syntax of this command is as follows:

unalias aliasname

For example, we will remove the alias ‘edit’ which was created in an earlier example:

unalias edit

You also have to delete the alias command using a text editor from the ~/.bashrc file.

How-to remove all aliases

unalias with -a option, removes all the aliases.

$ unalias -a
$ alias

4. Make Aliases Permanent

The alias ‘edit’ remains in effect only during the current login session. But whenever you logs out or reboot the system the alias ‘edit’ will be gone. Just add alias to your ~/.bashrc file to avoid this problem, and then enter:

vi ~/.bashrc

The alias ‘edit’ for the current user can be made permanent by entering the following line:

alias edit=’vim’

Save and close the file. We can create aliases for all users with just put in the /etc/bashrc file.

Avatar photo

Asif Khan

Responsible and proactive professional with more than 13 years of experience in IT systems, open source software applications, DevOps, Linux systems, and cloud operations. My main goals are to automate things, keep them safe, and make sure they are strong. I am very good at planning and building the infrastructure for services that people really want. I was drawn to the fast-paced world of cloud computing because it has resources that can be scaled up or down as needed. One of my best skills is being able to use a lot of different DevOps tools to set up, release management, and microservices ecosystems, as well as for provisioning, orchestration, and configuration management.