2

I accidentally did this:

command > ~/.bash_profile

Instead of

command >> ~/.bash_profile

I know, I'm an idiot. Is there a way to recover the old .bash_profile file?

Thanks a lot for your help

PS: The machine is a macbook pro with Leopard.

Pablo Fernandez
  • 665
  • 1
  • 5
  • 8

3 Answers3

3

Unless you had Time Machine or some other backup of the file, it's gone.

If that was the original .bash_profile, according to this page, the default setup for users is stored in /System/Library/User Template/English.lproj, you should be able to get another copy of the original from there. Or just create a new user and take theirs.

DerfK
  • 19,493
  • 2
  • 38
  • 54
2

I've just got the same accident. This is how I could recover some lost data in my bash_profile. Assume you are still in the terminal where you've just run the bad command:

$ echo 'something' > ~/.bash_profile

For PATH and ENV variables, use this command:

$printenv

For aliases, use this command and copy the ouput:

$alias

For functions, use this command to list all the function names:

$compgen -A function

And use this command to show the content of a function name:

$type function_name

Hope this helps some other people :)

vinhhungle
  • 21
  • 2
1

It's possible but unlikely. The effort involved in recovering it will most likely be harder than simply rewriting it or recovering it from a backup.

user9517
  • 115,471
  • 20
  • 215
  • 297