How do I restore the default bashrc?
I have accidentally overwritten .bashrc
. I did the following
echo 'export EDITOR=/usr/bin/nano' >> /etc/bashrc
Bur I accidentally typed >
instead of >>
. I guess, it was a bad idea.
I am still able to log in by using this trick (hit Ctrl+C
before the .bashrc will be fully executed). But how do I restore it to the default .bashrc
?
I'm running CentOS 6.5 x86_64. If the default bashrc file is there in the distribution somewhere, I cannot find it.
Solution 1:
Move the damaged file out of the way, then reinstall the package that provides the damaged file.
mv /etc/bashrc /etc/bashrc.damaged
yum reinstall $(rpm -qf /etc/bashrc)
Solution 2:
Did you overwrite the .bashrc
in your user directory? Or the systemwide .bashrc
stored in /etc/skel/? You can always copy the default
.bashrcfrom
/etc/skel/` like this:
cp /etc/skel/.bashrc ~/.bashrc
EDIT: In the comments below the original poster states:
I did echo export EDITOR=/usr/bin/nano > /etc/bashrc when I should have written >>.
Okay, that explains what went wrong. But in general, anyone who suggests Linux/Unix system files be adjusted by using >>
concatenation should be publically shamed forever. The problem is exactly what you ran into. All that >>
does is append the contents to the left of >>
to the item top the right of >>
. It seems slick and fast, but in my humble opinion you are much safer just opening the file in an editor and adding whatever you need to add to the end of the file. Just do this:
sudo nano /etc/bashrc
Add whatever you need to add to that file, save it and move on.
Solution 3:
It looks like /etc/bashrc is in this package: setup-2.8.14-20.el6_4.1.noarch.rpm
You could try reinstalling this rpm. (which could have unintended consequences)
Or you could download the source rpm, and copy out the file manually:
Source RPM : setup-2.8.14-20.el6_4.1.src.rpm
http://www.wikihow.com/Extract-RPM-Packages
http://rpm.pbone.net/index.php3/stat/4/idpl/25011386/dir/centos_6/com/setup-2.8.14-20.el6_4.1.noarch.rpm.html