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.

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.

First:

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
add comment

2 Answers

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 http://stackoverflow.com/a/5163260/1626345.

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

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
add comment

Your Answer

 
discard

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.