The history
command lists out all the history for the current session. Like:
1 ls
2 cd /root
3 mkdir something
4 cd something
5 touch afile
6 ls
7 cd ..
8 rm something/afile
9 cd ..
10 ls
11 history
In order to search items of interest, I can pipe history
with grep
like
history | grep ls
1 ls
6 ls
10 ls
I can also view last 3 commands like:
history 3
11 history
12 history | grep ls
13 history 3
But how do I get a specific range of history? For example something like:
history range 4 7
4 cd something
5 touch afile
6 ls
7 cd ..
x
commands then pipe tohead
.history | grep something
shows results of commands numbered123 234 345
in history and I may not know the number of last command executed (history
in this case). My last command could be numbered 400, 500 or whatever. So first I have to check that number, figure out the difference, list the lastx
commands and then pipe tohead