Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When using the command I know a friend of mine who used to re-use last part of previous command. He unfortunately moved far away and I can't get hold of him.


cp -r folder ~/folder

Then he was re-using ~/folder in a very quick way.

Anyone who knows how to do this?

share|improve this question
up vote 7 down vote accepted

The variable $_ is used to substitute the most recent parameter.

So, in the example you mentioned, you'd do something like:

cp -r folder ~/folder
cd $_

cd $_ will change directory to the most recent parameter i.e. ~/folder.

For more such variables, have a look at

share|improve this answer
beautiful if you ask me – don.joey Mar 7 '13 at 15:07
Is there any difference between $_ and !$? – Yamaneko Mar 7 '13 at 15:49
No, normally, they function the same. – green Mar 7 '13 at 16:06

With the arrow up key you can quickly access the last command you used.

With Ctrl+R you can do a 'reverse-i-search'. That means you just type in any letter or word of a command you already used and it will show up when enough identifying input is given.

Typing !$ will insert the last word (or a whole path if it's one) of the last command you used. See here for a lot of useful tips. I just bookmarked it. :)

If you are planning to do this quite often with the same paths, this tutorial might help.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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