Search code examples
macosterminalzshzshrc

Erased .zshenv file by mistake


I have erased/cleared my .zshenv file by running command echo > .zshenv unfortunately. I am not a pro in terminal and commands. Can I get back my old .zshenv file by any commands?

Please help.

Thanks in advance.


Solution

  • Since you are on macOS, you can get it back through Time Machine: https://support.apple.com/en-in/guide/mac-help/mh11422/11.0/mac/11.0

    In future, you might also want to add

    setopt NO_CLOBBER
    

    to your .zshrc file. This prevents > from overwriting existing files. With NO_CLOBBER set, only >| or >! can overwrite existing files.

    Additionally, you might want to get into the habit of using >> instead of >. >> can create new files, just like >, but unlike >, if the file already exists, instead of overwriting it, >> will simply append text to the file.