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?

2 Answers 2


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

Afterwards, you may want to instruct zsh to re-read the history form the recovered history file

fc -R .zsh_history
  • 12
    May I ask what does the command 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, 2016 at 5:15
  • 3
    For more details about the fc command, see here and here. The -R option is not present there, but zsh completion lists, among the options, -R -- read history from file Aug 23, 2016 at 11:41
  • 1
    Anyone knows what this error could have been caused by? Jan 15, 2018 at 21:31
  • 3
    @hugronaphor In my case it was that I had to do a hard shutdown of my laptop. This caused some issues for me as I did this during a disk write operation and one of the things that got corrupted was my zsh file among other things.
    – RyanNerd
    Jan 26, 2018 at 20:59
  • 2
    For the correct 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, 2018 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)

  • Of course, you can also use any other editor like ` emacs` or ` nano` … 😜
    – rugk
    Jun 13, 2020 at 13:10
  • 2
    @rugk Over my dead body. /s
    – aksh1618
    Jun 14, 2020 at 9:56
  • This solved for me! I also had some special characters (converted from windows format to UTF-8) that had gone bad. Erasing them all solved it. Thanks!
    – OCarneiro
    Jul 29, 2022 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .