What is alias?

The alias command allows you to create your own names or abbreviations for commands by performing string substitution on the command line according to your specifications. Aliases are recognized only by the shell that invokes them; spawned processes do not “inherit” them.

To configure your shell with aliases you have to edit your .bashrc or .zshrc :
Note: rc stands for “runcom” i.e. run command not “resource configuration” though it act as a configuration file.

Edit RC (Run Commands) files

Open with vim

vim ~/.bashrc
vim ~/.zshrc

After you have edited this files you have to use

source ~/.bashrc
source ~/.zshrc

to load them for your current session. From next time this aliases will be loaded atomatically you login to shell.

Navigate up the directory:

Append this following line in your shell

alias ..="cd .."
alias ...="cd ../../"
alias ....="cd ../../../"

Now from your shell you can use ‘..’, ‘…’ and ‘….’ to navigate up the directory.

or try this script

for i in 1 2 3 4
    alias $baseName="cd ${dotSlash}"

Creating your own command

lets start with this

alias today='date +"%d-%m-%Y"'
alias time='date +"%T"'

Now try them

➜ $ today
➜ $ time

Get top process eating memory

alias psmem='ps aux | sort -nr -k 4'
alias psmem10='ps aux | sort -nr -k 4 | head -10'

get top process eating cpu

alias pscpu='ps aux | sort -nr -k 3'
alias pscpu10='ps aux | sort -nr -k 3 | head -10'

Network Commands

Stop after sending count ECHO_REQUEST packets

alias ping='ping -c 5'

# Do not wait interval 1 second, go fast #

alias fastping='ping -c 100 -s.2'

No need to use full command

# if user is not root, pass all commands via sudo #
if [ $UID -ne 0 ]; then
            alias install='sudo apt-get install'
            alias update='sudo apt-get update'

Edit configs

alias zshconfig="vim ~/.zshrc"
alias bashconfig="vim ~/.bashrc"

## Colorize the ls output ##

alias ls='ls --color=auto'

# To play video files in a current directory
# cd ~/Download/movie-name
# playavi or vlc

alias playavi='mplayer *.avi'
alias vlc='vlc *.avi'

# play all music files from the current directory #
alias playwave='for i in *.wav; do mplayer "$i"; done'
alias playogg='for i in *.ogg; do mplayer "$i"; done'
alias playmp3='for i in *.mp3; do mplayer "$i"; done'

Remove an alias

➜ $ unalias aliasname

Now you can try your own aliases.