Append The Previous Terminal Command 0

Terminal

Share
Append The Previous Terminal Command

Hey

This is just a quick post, I don’t have much time today. In short this post is about quick recovering from those little slips you make while using Terminal. Every so often you will be writing a line in Terminal, hit enter and then forget something and end up with a syntax error. This is really annoying, but you can correct this quickly with out having to press up on the keyboard and trying to correct the whole line.

For example if you forget to add something to the beginning of the previous command you can use the following.

cd !!

this means that the previous command will run (defined by !!) put will add “cd” to the beginning of the command.

You can also do this in reverse if you add !! to the beginning of the command like so.

!!downloads

That will run the previous command and then append “downloads” to the very end, spaces are taken into account. This is most useful when you are writing change directory commands and forget something at the end.

As a magic bonus you can also run the previous command at the same time at the front and the back of the new piece of information.

!! cd!!

Although it probably isn’t very useful if you end up doing that, you should probably try and get it correct first time round. You can repeat !! as many times as needed.

A little Terminal trick which is useful as a temporary variable if you are writing a line of code, or you forget something important.

If you want to take your skills with Terminal a bit further I recommend you check out the Terminal Category on this site. If you fancy reading a book there is a couple on Amazon that I regularly see mentioned and recommend, O’reilly Unix Geeks and Unix Under the Hood both are designed for Mac OS X and take Terminal further.


If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips