Command history and automated repeats (bash)
Posted: 04 Sep 2011, 13:05
We often put together complex commands -....... and then we forget them
How can we reuse those brilliant pieces of (lacking) know how or how can we find them again? You know -that brilliant tip from the guru on that site that you forgot - needless to say you forgot the command itself......but it was something with urpmi
Fear no more the command will come to your rescue 
It will give you the list over all commands executed and in historical order:
It does not care if the command was correct or not - this is the history right or wrong -basta!
Now i find that
Like this:
And wonder of all wonders it is executed directly
Now this can be a bit dangerous because I do not get a peek at the command first - it just executes. And that could potentially
So how do I get to have a look at the command first?
Will do it! By adding the :p (for peek) you can have a look at it first.
To add the previous command you can do a:
or To add the command before that you can do a: and so on.
So to have a peek at three commands back what do we do?
You guessed it:
But it gets better
I am lousy with numbers and I don't even remember what I did one command back
But I know it was starting with sudo urpmi so I do a:
And there it goes - doing the
If I want to have a look at the command starting with urpmi?
Or the last command starting with pacman (Arch): etc etc...
You do not even need to remember the entire command. If you want commands executed with ssh and only remember ss just do a:
It will output something like this;
I just needed to write this down in case I forget
How can we reuse those brilliant pieces of (lacking) know how or how can we find them again? You know -that brilliant tip from the guru on that site that you forgot - needless to say you forgot the command itself......but it was something with urpmi
Fear no more the
Code: Select all
history
It will give you the list over all commands executed and in historical order:
It does not care if the command was correct or not - this is the history right or wrong -basta!
Now i find that
hard to remeber so I will just execute it by executing its number in the history table.sudo urpmi --auto-update -a
Like this:
Code: Select all
!991And wonder of all wonders it is executed directly
Now this can be a bit dangerous because I do not get a peek at the command first - it just executes. And that could potentially
So how do I get to have a look at the command first?
Code: Select all
!991:pWill do it! By adding the :p (for peek) you can have a look at it first.
To add the previous command you can do a:
Code: Select all
!!Code: Select all
!-1Code: Select all
!-2So to have a peek at three commands back what do we do?
You guessed it:
Code: Select all
!-3:pBut it gets better

I am lousy with numbers and I don't even remember what I did one command back
Code: Select all
!sudo urpmiAnd there it goes - doing the
Code: Select all
sudo urpmi --auto-update -aIf I want to have a look at the command starting with urpmi?
Code: Select all
!urpmi:pOr the last command starting with pacman (Arch):
Code: Select all
!pacman:pYou do not even need to remember the entire command. If you want commands executed with ssh and only remember ss just do a:
Code: Select all
!ss:pIt will output something like this;
Code: Select all
$ !ss:p
ssh viking@viking60-serverI just needed to write this down in case I forget

