Fix : ZSH corrupt error

Recently I had an issue with ZSH, whenever I open my terminal it shows some error that my .zsh got corrupted.

This is how the error looks like:

$ zsh: corrupt history file /home/myusername/.zsh_history

How to fix this issue?

It happens when you make some changes to the ZSH history file, or you delete it improperly.

So I found a way to fix it. You need to rename the history file and then delete the new file. Just copy-paste these commands in your terminal:

$ cd ~

$ mv .zsh_history .zsh_history_bad

$ strings .zsh_history_bad > .zsh_history

$ fc -R .zsh_history

Now reboot your system

$ sudo reboot

Or

Another simple way to remove the history file (note that this will remove your terminal history) –

echo $HISTFILE

And

rm $HISTFILE

 

Issue fixed. If you face this error again then follow the same method.