Terminal Aliases

Sick of typing out long commands, bad at typing, forget commands from time to time or all 3 like me… then aliases are here to help.

Basically, you can use a handy short memorable alias for a long and possible complicated one in terminal by doing the following.

Open terminal, go to root ( cd ~/ ) and see if a file under the name .bash_login exists… if not create it.

Open this file in vim, enter your aliases like so…
alias dev1=’ssh username@serverhostname.com’
alias dev2=’ssh username@anotherserverhostname.com’

So now each time I enter dev1 into the terminal, I will be ssh’ing into my server, or dev2 to ssh into another one without having to recall the hostname and such… sweet.

You can add as many as you like for any command.

HANDY TIP: Enter the alias !=history and now you each time you type ! plus some text, the terminal will  figure out which command to call based on your terminal history and the text you entered.

HANDY TIP #2: Use CTRL+R to search through any of your previous commands, you can insert any part of the command… super!
Thanks Donncha

5 thoughts on “Terminal Aliases

  1. Try ctrl-r and start typing a fragment from a previous command. It doesn’t even have to be the first character!

    Press ctrl-r again to cycle through the choices BASH finds 🙂

  2. I think read about ctrl-r a few years ago but I only started using it a lot last year, and I’ve been using Linux for over 15 years! Up until then I was using ! all the time but of course this is more flexible.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s