当我history在Bash中运行时,我得到了大量的结果(1000+).但是,当我运行historyzsh shell时,我只得到15个结果.这使得在zsh中的grepping历史大多无用.我的.zshrc文件包含以下行:
HISTFILE=~/.zhistory
HISTSIZE=SAVEHIST=10000
setopt sharehistory
setopt extendedhistory
Run Code Online (Sandbox Code Playgroud)
如何修复zsh以使我的shell历史记录更有用?
UPDATE
如果在zsh中我打电话给history 1我得到我的所有历史,就像我在Bash中一样history.我可以使用别名命令来获得相同的结果,但我想知道为什么history在zsh和Bash 中表现不同.
mkl*_*nt0 24
该任择议定书已经表示在更新的问题的答案:history在不同的行为bash比它在zsh:
简而言之:
history仅列出最近的15个历史记录条目history 1列出所有 - 见下文.history列出所有历史条目.
可悲的是,传递数字操作数的history行为也不同:
history <n>显示所有以<n> - 开头的条目,因此history 1显示所有条目.history -<n>- 注意-- 显示<n>最近的条目,因此默认行为是有效的history -15)history <n>显示<n>最近的条目.history不支持从条目号列出;您可以使用fc -l <n>,但必须存在特定条目<n>,否则命令失败 - 请参阅下文.)可选背景信息:
history有效(实际上)是别名fc -l:seeman zshbuiltins
man zshallhistory是它自己的命令,其语法不同于fc -l
man bashfc -l <fromNum> [<toNum>]列出给定范围的历史条目:
<fromNum>必须存在特定条目.fc -l 1在zsh中工作以返回所有历史条目,而在bash中它通常不会,因为条目#1通常不再存在(但是,如上所述,您可以使用history不带参数来列出bash中的所有条目).小智 13
也许很晚了,但是看到这篇文章并尝试应用它,但失败了....所以实际上,将其放入.zshrc:
alias history='history 1'
Run Code Online (Sandbox Code Playgroud)
在用完之前你会看到任何东西HIST_SIZE。查找我使用的命令(更改后.zshrc)
history | grep "my_grep_string"
Run Code Online (Sandbox Code Playgroud)
#set history size
export HISTSIZE=10000
#save history after logout
export SAVEHIST=10000
#history file
export HISTFILE=~/.zhistory
#append into history file
setopt INC_APPEND_HISTORY
#save only one command if 2 common are same and consistent
setopt HIST_IGNORE_DUPS
#add timestamp for each entry
setopt EXTENDED_HISTORY
Run Code Online (Sandbox Code Playgroud)
这是我的设置,可以正常工作