Ubuntu – Using last part of command for next command

command linehistory

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?

Best Answer

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