1 min read

Recover Corrupt ZSH History File

Very often I got this error when opening the terminal session (normally after the computer wasn't shutdown properly):

zsh: corrupt history file /home/agung/.zsh_history

There is a simple fix for that, thanks to this article. Just invoke this:

#!/usr/bin/env zsh
# George Ornbo (shapeshed) http://shapeshed.com
# License - http://unlicense.org
#
# Fixes a corrupt .zsh_history file

mv ~/.zsh_history ~/.zsh_history_bad
strings -eS ~/.zsh_history_bad > ~/.zsh_history
fc -R ~/.zsh_history
rm ~/.zsh_history_bad