I'm using fish shell but the history command in this returns something like

cd Downloads
mkdir new_folder

whereas, the same thing in zsh would return

399 ls
400 cd Downloads
401 ls
402 mkdir new_folder

How can I get these numbers in fish too?


1 Answer 1


history | cat -n would do it.

But don't forget that if you remove lines from the history you will not remove the number (because the historyfile of fish doesn't save them).
For example: When you remove the line cd Downloads the 2nd ls will become 400.

zsh on the other hand saves the numbers in ~/.zsh_history file so here the 2nd ls will stay 401

When using fish you might be interested history --show-time. It won't show the number, but it will show the time when every command was executed.

Edit: To answer your comment: history | cat -n | grep 315

But more useful: history | cat -n | less followed by /, 3, 1, 5 and Enter.
That way you can easily see the commands right before and right after that specific command by using the up/down keys.

(I added the comment-answer to the original answer because key-formatting fails in comments)

  • When using zsh, I sometimes use numbers to navigate through history using grep <number> to find the nearby commands to a particular one, say ls which is at 320. So I use history | grep 315 to check the commands typed before that. Is there a way to achieve this?
    – Eagle
    Commented Aug 25, 2020 at 0:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .