Every time I try to make my Zsh history file (.zhistory file) a symbolic link to a file (previously existing .zhistory file) that lives in another folder, Zsh deletes the symbolic link and makes it a regular file.

I have tried creating the symbolic link in Bash and then switching back to Zsh, but Zsh will still always remove the link and copy the file instead.

Why is this? How can I have my .zshistory file live somewhere else ? (in my case a git repository not located in the home directory)

  • 1
    Probably zsh is recreating the file each time. – vonbrand Jan 30 '14 at 19:44
  • @vonbrand It actually copies the file using the symlink, instead of creating an empty one from scratch. – Amelio Vazquez-Reina Jan 30 '14 at 21:18

The easiest way to do this would be to not use links at all. The location of the zsh history file is determined by the value of $HISTFILE. So, to have that backed up, change it from the default value to a file in the watched directory. Add this line to your .zshrc:


Now, copy the existing file over to the new location and any new shell you open should use the new file for saving the history.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.