How to create short-cut or alias of linux or unix command ?

Tarikul Islam
Oceanize Lab Geeks
Published in
2 min readMay 5, 2018

Usually we use lot’s of command in our daily work. Using those same command more and more time. By using some alias or command we can easily handle those commands

What Are Aliases?

Aliases are shortcuts refer to commands. For example (and a dead simple one at that), if you use Terminal to do anything, like open hosts file with vi , we probably uses

sudo vi /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

But after making alias i just use vhostEdit .

alias vhostEdit='sudo vi /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf'

Usefulness of making command Alias

  1. We can speedup our works
  2. No chance to forgot the command structure just need to remember the short-cut
  3. You can hide your secure information into the command alias.

How to make alias or command ??

There are 2 way to make alias or command

  1. Adding alias command in ~/.bash_profile or ~/.bashrc file
  2. Write command in /usr/local/bin folder

Some useful alias

## a quick way to get out of current directory ##
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'
##Server connect with SSH
alias connect-dev='ssh -v -i ~/secriet-key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-east-2.compute.amazonaws.com'
alias connect-prod='ssh -v -i ~/key-prod.pem ec2-user@ec2-xxx-xx-xxx-xx.us-east-2.compute.amazonaws.com'
## Set vim as default
alias vi=vim
alias svi='sudo vi'
alias vis='vim "+set si"'
alias edit='vim'
##Git Aliasalias g="git status"
alias ga="git add"
alias gaa="git add ."
alias gau="git add -u"
alias gc="git commit -m"
alias gca="git commit -am"
alias gb="git branch"
alias gbd="git branch -d"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gt="git stash"
alias gta="git stash apply"
alias gm="git merge"
alias gr="git rebase"
alias gl="git log --oneline --decorate --graph"
alias glog="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
alias glga="git log --graph --oneline --all --decorate"
alias gb="git branch"
alias gs="git show"
alias gd="diff --color --color-words --abbrev"
alias gdc="git diff --cached"
alias gbl="git blame"
alias gps="git push"
alias gpl="git pull"
alias gb="git branch"
alias gc="git commit"
alias gd="git diff"
alias go="git checkout "
alias gk="gitk --all&"
alias gx="gitx --all"

By this way you can make lot’s of command alias which save your time

--

--