I've accidentally overwritten my
Does anyone have a "sample" one I could copy, or know where I might be able to find one?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
If your terminal window is still open, you can save the current environment settings to rebuild. The recovered file will contain more information than you may have defined yourself, so remove the parts you don't need:
Defined vars and functions:
$ declare > .bash_profile.recovered
$ alias >> .bash_profile.recovered
Search for dot_files in Google or Github if you like a sample one.
If you like to restore it, you could try to get it from your TimeMachine backup (if present)
There is a backup located at:
Just copy it over your current file.
You can try to recover it using TestDisk.
If that doesn't work, type:
x56~:$ alias >> ~/.bash_profile
x56:~$ echo "PATH=$PATH" >> ~/.bash_profile
to at least recover your PATH and aliases, which you can paste in your new profile file.
Unfortunately this is what revision control is for. There is no way to undo modifications, while deletes through finder are actually moves to the trash.
Use TimeMachine in the future. Aside from this, it will also give you piece of mind when your current hard drive dies. I know people facing this problem now and if they only invested $30-$50 into a backup hdd, the problems would not happen. I recommend you just learn from this and back up using timemachine periodically.
Github as mentioned by Ian C is a great place to back your dotfiles, also you can find dotfiles from others'. Version control to the rescue here, don't know how many times it saved me, but definitely more than I can remember. The advantage of TimeMachine is that it also does version control, problem is that its stored by snapshot time, not logical version.
If you can't use Terminal to access your
~/.bash_profile (e.g. it's corrupted) you can use BBEdit or any other GUI editor that can open files from a location and open your corrupted file in order to fix it.
BTW. if you know the location and name of any hidden file, this method can be used to open it (assuming it is a text based file).
This method works only if you saved the
bash_profile file to a point where you want to go back in TextEdit, doesn't work if edited using vi or nano (thanks to @nohillside for pointing this out). You can open the file using TextEdit (for ex:
open ~/.bash_profile) and click on
File -> Revert To -> Browse All Versions... and then select the version you want to revert back to.