4

I used zsh and when I run Ctrl-R to search history command, I can only get the command executed in this session, but can't search all the history commands. I know there is a .bash_history file in bash to store all the history commands and we can do this search in bash.

Is there any way to do this in zsh?

shangyin
  • 526
  • 1
  • 4
  • 14

4 Answers4

1

Zsh does not save history to a file by default, that's why when changing session your history is removed. You will have to put in your ~/.zshrc file the following:

HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt appendhistory
Nahuel
  • 158
  • 8
0

Just search the history file:

  % egrep <regexp> ~/.zsh_history

or

  % less ~/.zsh_history

and use / command to search

bguiz
  • 27,371
  • 47
  • 154
  • 243
0

Alternatively to Ctrl-R you may write the first characters of the command then press key to scroll up the command lines history that starts with the written first characters up to the first usage

Eladio
  • 369
  • 1
  • 5
0

To search through history in all sessions, you'll need to enable several options. The zshoptions manual page has a History section that lists relevant options.

SHARE_HISTORY is one option which will share history between sessions. With this enabled, you should be able to search (using Ctrl-R or history) through commands run in this and other sessions.

simont
  • 68,704
  • 18
  • 117
  • 136