Reconstructing .bashrc from running session

I accidentally deleted my .bashrc. I still have the terminal running. What settings can I recover?

I already have the aliases (from the alias command). I assume that all ifs and cases are gone, but I want to retrieve the variables. How can I do that? (other than having to type them out). Also what else can I recover?


If you had a default .bashrc file w/o your own tweaks you can recover the original one from the skel directory:

cp /etc/skel/.bashrc ~/

The skel directory has (or should have) the default settings for new users. When a user is created the contents of the skel dir are copied to the new user home

Added a description of how to check what could have been in the user's bashrc file that is not in a default bashrc file:

In case you had a tweaked .bashrc file and since env will dump all the session settings (lot of stuff) which may proceed from several files (/etc/bashrc, /etc/profile, .profile,....). you need to get what was generated from your own bashrc that is different from the default bashrc, and discard all what is generated from other bash sourced files:

Based on the 'env' answer posted by silviud and as long as you still have the old terminal open you can save the env output to a file. Then open a new shell and compare old env to new env hence showing what was generated from your .bashrc.

For example, in your old terminal dump the env to a file:

env > oldenv

In a new shell get what has changed now that .bashrc is the default one:

comm -3 <(env) oldenv

Edit the .bashrc obtained from the skel dir to add the differences you have got from the above command.

HTH


shell$ env
# will tell you all the settings you have into that terminal 
# the alias is handy as well for all the aliases you have

This happened to me, really scary! I ran "env" to get all of the enviroment variables and also the command "alias" will print all of your aliases, which aren't in your environment.

So run:

env

and

alias

and copy them into the bashrc skeleton file.

Now quickly put your .bashrc into git:

cd ~
git init
git add .bashrc
git commit -m "added .bashrc"