Skip to content

Instantly share code, notes, and snippets.

@musale
Last active September 24, 2024 05:50
Show Gist options
  • Save musale/751cfb132fe6ad05d3a5cc306d72465c to your computer and use it in GitHub Desktop.
Save musale/751cfb132fe6ad05d3a5cc306d72465c to your computer and use it in GitHub Desktop.
How to fix and recover a “corrupt history file” in zsh
# move to home directory
cd ~

# move the .zsh_history file into another .zsh_history_bad file
mv .zsh_history .zsh_history_bad

# write all printable strings into a new .zsh_history file
strings .zsh_history_bad > .zsh_history

# reload the history
fc -R .zsh_history

If you found this helpful, don't hesitate to buymeacoffee

@z2687737
Copy link

thank you. problem solved.

[ # move to home directory cd ~ ]
after 2022 no more CD command?
I used [ $ sudo su > kali ] to get to the root directory

@wallace-sf
Copy link

Thanks bro 💪

@Ivcannons00420
Copy link

works in 2023 thanks

@msucevan
Copy link

Thanks!

@CharlesNkdl
Copy link

Still works !

@Arios509
Copy link

Thanks, but i wonder how does this happened? Does anyone know why?

@astyd256
Copy link

🔥

@jgproc
Copy link

jgproc commented May 31, 2024

Thanks!

@anormalmeatperson
Copy link

still works, thanks

@zyyAdrian
Copy link

Thanks!

@Kayo4life
Copy link

@Arios509

Thanks, but i wonder how does this happened? Does anyone know why?

Typically you didn't shut down your computer correctly. Another way you can fix this is just opening your zsh history file in a text editor and removing the corrupted parts. Corrupted parts usually look like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment