Welcome

This blog has permanently moved to
https://boseji.com

Contact Form | Email Address

© 2018 All rights reserved by Boseji

Thank you for all your support.

Sunday, May 27, 2012

Shortcut shell commands for Linux

We were trying to evaluate if there is any quick way to give some short cut commands in Linux shell. We wanted to have this without the need to create many script files and path jugglery.

Then we found the solution by adding command 'alias' in the local profile for the shell.

We know that the default shell configuration is located at ~/.bashrc
This file executes each time we enter the bash shell. So if you add the alias commands to this file then you can access them any time you use the shell.
It is generally  recommended to add the alias commands to the end of this file.

The syntax for the 'alias' is in the following way:

alias {shortname}='{actual command}'

Let us have a look at the use-case scenarios to shows how useful this can be:
  • Changing to a particular project directory which is long
    • eg: /home/username/Documents/githubrepos/Kicad-tools
    • This needs to be  typed all the time to reach that place
    • add the following:
alias proj='cd /home/username/Documents/githubrepos/Kicad-tools'
  • Error while typing 'cd..' instead of 'cd ..' to change to upper directory
    •  add the following:
alias cd..='cd ..'
  • Emulation of favorite dos commands
    • eg: dir, md, deltree
    • add the following:
alias dir='ls -alh'
alias md='mkdir'
alias deltree='rm -rf'
  • Shortcut commands for git operations 
    • eg: git add transformed to ga or gita
    • eg: gitk --all transformed to greal
    • add the following:
alias ga='git add'
alias greal='gitk --all &'
This list can go on of the single short commands that can be implemented in this manner.

There is a detailed tutorial available from NixCraft site.

No comments:

Post a Comment