History-command

History is nice. It shows your inputs in terminal. You can also run any command from the listing with !.

So, a history list is printed with:

$ history

We can of course limit our query set with piping:

$ history |grep cd
  129  cd ..
  517  cd ..
  518  cd ..
  522  cd abc/
  525  history |grep cd

And then we can run the command we've long since forgotten with:

$ !129
cd ..

But wait! There's more cool stuff, since everything can be chained together, we can run multiple commands in a row. There could be a command sequence we have used to do some nice things, and we can replicate it with history:

$ history |grep cd
  129  cd ..
  517  cd ..
  518  cd ..
  522  cd abc/
  525  history |grep cd
  526  cd ..
  527  cd -
  528  history |grep cd

kalle.tolonen@computer ABC ~/fancy_directory/abc (main)
$ !526 && !527
cd .. && cd -
~/fancy_directory/abc

All articles


Comments

No published comments yet.


Add a Comment

Your comment is held for review before it appears publicly.

Your email is never published or shared.

Up to 2,000 characters.

Tick the box, then click Submit right away (Google expires the check after about two minutes).