Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've accidentally overwritten my ~/.bash_profile file.

Does anyone have a "sample" one I could copy, or know where I might be able to find one?

share|improve this question
A good time to mention that GitHub is an excellent place to store your dotfile customizations. For an example of how to do this see: – Ian C. Sep 26 '11 at 13:19
Tip: Use Time Machine to make regular backups of your files so you can recover them if accidentally deleted or edited. The single best investment you can make in your computer is a backup plan. – Chris Page Sep 26 '11 at 14:43
Just FYI, I don't think os x has a "default" .bash_profile. – Robert S Ciaccio Sep 26 '11 at 20:32
This really could have been answered by google ("sample bash_profile"). The 3rd hit provides a rather massively complete sample: – user10355 Sep 26 '11 at 21:28

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)

share|improve this answer
or any other backup - if no backup start producing one now before doing anything else – Mark Sep 26 '11 at 12:41

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.

Good luck.

share|improve this answer

By default, hidden files cannot be seen in Time Machine or Finder. If you are trying to restore your file from a backup but can't see the .bash_profile file listed, you need to enable the display of hidden files in Finder.

To enable the display of hidden files type the following two commands into Terminal

defaults write AppleShowAllFiles YES
killall Finder

Now perform your restore from your backup of your home directory.

To make these files hidden again, type the following commands into Terminal

defaults write AppleShowAllFiles NO
killall Finder

Note: Case is important in the commands above.

share|improve this answer
Or just open Terminal and use cp – patrix Sep 27 '11 at 11:21

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).

share|improve this answer

There is a backup located at:


Just copy it over your current file.

share|improve this answer
Might be worth to add that this is the standard template, so any changes the user made to his local .bash_profile will not be reflected in it. – patrix Feb 18 '14 at 12:51

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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