History-command

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


Kalle Tolonen
May 19, 2025


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

Comments

No published comments yet.

Add a comment

Your comment may be published.