Unfortunately I just overwrote my .bashrc
with
echo "command" > ~/.bashrc
as opposed to appending via
echo "command" >> ~/.bashrc
.
Not a huge throwback as I am newer to working in the terminal. HOWEVER I AM WONDERING if it is possible to recover my .bashrc
before I restart my terminal session!
Is there a location where a session's commands are stored? If so - how can I extract my custom scripts?
Expecting for the worst of news, hoping for the best of news! I'm running an Ubuntu 13.04 box and the session is in Guake Terminal - if that changes things at all.
Cannot be recovered.
I suggest you to type
env
in your terminal to view the most important environment variables (like LD_LIBRARY_PATH, PATH, PYTHONPATH, CLASS_PATH, JAVA_HOME, and so on ...) and add them back into a new .bashrc file.You can start from a copy of
/etc/skel/.bashrc
as a minimal file.For the future you may consider using a version control system such as git or hg in order to save previous versions of files such as
~/.bashrc
. Then if you happen to do a>
rather than>>
in the future you should be able to recover the file back to the point the last time you commited it to the version control.An example of how to set this up for
git
would be:You can't completely recover. But you can partially recover using
set
.If you run
set
on the same terminal you'll be able to get a whole list of custom scripts and other environment variables set. And in that, it's upto to differentiate the ones that were part of.bashrc
and others typed on that terminal. But you won't be able to recover the commands which used to be executed as part of bash login.Assuming you built your
.bashrc
with a bunch of similarecho
commands and you just want to retrieve them:If you run
history
, you should be able to retrieve the previous commands. For more information, seeman history
.In your case, you might find the output of
history | grep bashrc
useful.