After a reboot, I started seeing a message when loading the shell:
zsh: corrupt history file /home/myusername/.zsh_history
How can I recover from this situation and potentially recover some of the history?
After a reboot, I started seeing a message when loading the shell:
zsh: corrupt history file /home/myusername/.zsh_history
How can I recover from this situation and potentially recover some of the history?
Found a blog post describing a fix that appears to work for me, while restoring my missing history:
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history
fc -R .zsh_history
mean? I've tried man fc
and it tells me that No manual entry for fc
, and neither could the fc -h
tell me more than the usage. Thanks.
– kenshinji
Aug 5 '16 at 5:15
-R -- read history from file
– Jeffrey Lebowski
Aug 23 '16 at 11:41
fc
documentation, see man zshbuiltins
, also available at zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html. As suggested by Jeffrey, "‘fc -R’ reads the history from the given file".
– Martin
Jan 29 '18 at 4:51
Simply removing random characters may also work:
vim .zsh_history
Remove any strange characters, which would most probably be near the end. (In my case I had a string of @
in the second last line, following a forced shutdown)
:x
(save and exit)
@
s in one line. I removed those and voila, the error is gone!
– illusionist
Jul 10 '18 at 3:38