Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

Is there any possibility to put some lines of code automatically to the terminal?

E.g. when I want to start Hamachi through the terminal and don't want to write long expressions every time.

Maybe this problem is easy to solve, but I am a beginner and would be thankful for help.

share|improve this question

marked as duplicate by Radu Rădeanu, karel, falconer, mikewhatever, Avinash Raj Jan 24 at 14:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

ah.. jeah, I take it you want to execute a command, not just put text into the terminal ;-)

In your home directory you find a hidden file named .bashrc This file holds a list of commands that are execute whenever you start a shell. You could append your command there...

But...

If you do this with complex stuff, this stuff will always execute when you open your shell. Depending on what it is this may make your shell unusable.. you don't want that.

What you want is an alias.

append to your .bashrc

alias i_can_remember_that="long and strenuous command"

everytime you type now i_can_remember_that into your shell, the long command gets executed. You can even pass additional parameters to the alias:

i_can_remember_that foo will in fact run long and strenuous command foo

The name of the alias can be choosen freely of course. Sometimes you even want to override another command that way. i.e. a common alias is:

alias ls='ls --color=auto -B' which replaces ls with a more complex call of itself.

share|improve this answer
    
And BTW. Don't mind your english, its fine and we are all citizens of the internet here ;-) –  Paul Hänsch Oct 27 '12 at 16:43
    
and more importantly, citizens of the world!!!! :P Ich bin ein Burger dem welt! (terrible german) –  drN Oct 27 '12 at 17:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.