Saturday, 2 May 2015

Fewer strokes with alias

In some cases, typing long lines in terminal can be a bit daunting. Whether it's a simple ssh command to connect to your favourite server or a long path to the log directory. Let's face it, we need to shorten things up.

The 'alias' command let's you do just that. ;)

Say we want to alias a long ssh command that connects you to the production mail server and call it as 'mail.prod': 'ssh vincent@192.168.154.230 -i ~/.ssh/secret.pem'

Here we go:

  1. Create a file named ~/.bash_aliases
  2. Add an entry:
    • alias mail.prod='ssh vincent@192.168.154.230 -i ~/.ssh/secret.pem'
  3. Bash doesn't have any idea of the command yet, you may want to re-open the terminal or execute the following to effect changes:
    • source ~/.bash_aliases

No comments:

Post a Comment