Search code examples
bashmacositerm2

How can I recover overwritten file in mac?


I accidentally did echo 'export BUNDLER_EDITOR=code' > ~/.bash_profile to add line to .bash_profile which overwritten previous scripts. How can I recover previous script? But I have iterm2 terminal open with previous .bash_profile setting, can we get content of .bash_profile from open terminal.


Solution

  • If you still have a Terminal open, you can maybe salvage some aspects of your environment.

    So, for your environment variables and function definitions:

    declare -p > $HOME/NEWPROFILE
    

    And for your aliases:

    alias > $HOME/ALIASES
    

    For more help on the declare command, use:

    help declare