How to fix and recover a "corrupt history file" in zsh?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping
--
Chapters
00:00 How To Fix And Recover A &Quot;Corrupt History File&Quot; In Zsh?
00:21 Accepted Answer Score 216
00:40 Answer 2 Score 31
01:02 Thank you
--
Full question
https://superuser.com/questions/957913/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#zsh #filecorruption
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping
--
Chapters
00:00 How To Fix And Recover A &Quot;Corrupt History File&Quot; In Zsh?
00:21 Accepted Answer Score 216
00:40 Answer 2 Score 31
01:02 Thank you
--
Full question
https://superuser.com/questions/957913/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#zsh #filecorruption
#avk47
ACCEPTED ANSWER
Score 217
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
ANSWER 2
Score 31
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)