Using last part of command for next command

Solution 1:

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.

Solution 2:

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.