WebMasterCampus
WEB DEVELOPER Resources

Linux alias Command

Learn Linux alias Command with examples


Linux alias Command

In Linux aliases are like custom shortcuts used to represent a command (or set of commands) executed with or without custom options.

To show list of defined aliases on your profile by simply executing alias command.

alias command Syntax

~$  alias

Default alias in Ubuntu


alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
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'

Creating Temporary Aliases Syntax

Type the word alias then use the name you would like to use to execute a command followed by “=” sign and quote the command you wish to alias.

~$ alias shortName="your custom command here"

Creating Temporary Aliases Example

~$  alias www_root="cd /var/www/html"

“www_root” shortcut take you to webroot directory. This alias will only be available for your current terminal session. If you close and open new terminal session, the alias will no longer be available.

Removing Temporary Alias

Removing alias added via the command line can be done using unalias command.

~$  unalias alias_name
~$  unalias -a [remove all alias]

Permanent Aliases

Permenant aliases needs to be save user’s shell configuration profile file. Shell configuration profiles can be following.

Profile Name File
Bash ~/.bashrc
ZSH ~/.zshrc
Fish ~/.config/fish/config.fish

The syntax is the same as creating a temporary alias. However you will be saving it in a file this time.

Open .bashrc file with your favorite editor like this.

~$  vim ~/.bashrc

It better to save them at the end of the file. Adding comments before your aliases will be helpful for future edits.

# My alias for web root directory 

~$  alias www_root="cd /var/www/html"

Save the ~/.bashrc file. The changes in profile bash file will reflect in next session.

Alias Available to Current Session

If you need to apply changes with current session then run the following command.

~$  source ~/.bashrc

Removing Permanent Aliases

To remove permenant just remove alias from bash profile and it will be avialable to next terminal session. For immediate impact use above source command.

Created with love and passion.