Show older or newer history items with the history command in zsh

command historyzsh

I typed in the history command and it showed me the last 10 commands executed by me. Now I wanted to see the last 20 commands executed by me so (after reading the documentation):

An argument of n lists only the last n lines.

I typed in history 20. This showed me all the commands starting from command number 20 to the current command which was somewhere around 2000. So I tried
history -20
and this works. It shows me the last 20 commands. But this is not what is said in the documentation.

Also history -d [offset] is supposed to delete the command on that offset. Even that does not work in my zsh.

This is straight out of my zsh shell :
enter image description here

Best Answer

In zsh, history is an alias for fc -l 1, so when you do history -20 it get replaced by fc -l 1 -20 which just won't work, so instead use fc directly:

➜  ~  fc -l -20
10095  grep -R PAPER /usr/lib/locale/
10096  man locale
10097  man 7 locale
10098  mc
10099  history
10100  history --help
10101  run-help history
10102  history 20
10103  history 1 20
10104  history -l 20
10105  fc
10106  history -l 20
10107  type history
10108  fc -l ..20
10109  fc -l -20
10110  history -l -20
10111  history -20
10112  fc -l -20
10113  type history
10114  fc -l 1 -20

and you'll be fine.

Related Question