Results 1 to 5 of 5

Thread: How to make command line shortcuts

  1. #1
    Join Date
    Feb 2005
    Location
    Vancouver, BC
    Beans
    329

    How to make command line shortcuts

    I ssh into a remote server several times each day. I dutifully type in:

    ssh myusername@remotehostname:/dir/I'm/looking/for.

    This takes forever. Is there a way to shortcut the typing (I already have password-less login configured, so at least that is quicker). Even just a shortcut for the username and hostname would be good. I do use the up arrow to find the previous entry, but often I've done dozens of other commands since I logged into the server, so sometimes the up arrow repeating takes longer than the typing...

    I'd like to be able to type: ssh web

    Thanks.

    Ross
    Ideas matter.
    Ross A. Laird

  2. #2
    Join Date
    Jan 2005
    Location
    Illinois USA
    Beans
    1,048

    Re: How to make command line shortcuts

    You could add a line such as
    Code:
    export WEB=myusername@remotehostname:/dir/I'm/looking/for
    In your ~/.bashrc file. (If you edit this in a console window, you must open a new one for changes to take effect.)

    Then you can do
    Code:
    ssh $WEB
    CloudRck.com - Host on CloudRck
    I sponsor open source projects and support users of such technologies. PM for details

  3. #3
    Join Date
    Oct 2004
    Beans
    21

    Re: How to make command line shortcuts

    Bash has a number of ways to reduce typing...

    First of all is aliases. Add something like the following to your ~/.bashrc file:
    alias sshtox='ssh user@remote:/dir/to/be/in'
    Logout and back in (or type 'source ~/.bashrc' at a shell) and you can now perform the command by just typing 'sshtox'.

    Another handy trick is to use Ctrl+r. This does a search through your recently typed commands. Hit Ctrl+r and start typing a part of the command you remember typing and bash will find it for you. Hit Ctrl+r again to scroll through the choices.

    Alternatively, DJ_Max's suggestion is just as valid.

  4. #4
    Join Date
    Jan 2005
    Location
    Adelaide, Australia
    Beans
    340

    Re: How to make command line shortcuts

    In general, Retrix's suggestion of using a bash alias is a good one. For the specific case of typing "ssh web" to get to your webserver, check out the documentation for ssh_config. You can modify your ssh config file so that it applies specific options when you ask to ssh to "web".

  5. #5
    Join Date
    Feb 2005
    Location
    Vancouver, BC
    Beans
    329

    Re: How to make command line shortcuts

    Thanks very much for all the tips and suggestions. This is going to make things much easier.

    Ross
    Ideas matter.
    Ross A. Laird

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •