Skip to content

Instantly share code, notes, and snippets.

@iambryancs
Created May 17, 2023 00:35
Show Gist options
  • Save iambryancs/77cf1d58fda0f306a365b1c2e9b66dae to your computer and use it in GitHub Desktop.
Save iambryancs/77cf1d58fda0f306a365b1c2e9b66dae to your computer and use it in GitHub Desktop.
Fix corrupt ZSH history file

Fix corrupt ZSH history file

Problem

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

Solution:

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

Explanation

  • mv ~/.zsh_history ~/.zsh_history_bad - move corrupt file
  • strings ~/.zsh_history_bad > ~/.zsh_history - use strings command to extract strings from corrupt file to new zsh_history file
  • fc -R ~/.zsh_history - use fc command to read history from the new zsh_history file
  • rm ~/.zsh_history_bad - delete corrupt history file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment