Server Fault is a question and answer site for system and network administrators. 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 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.

share|improve this question
up vote 7 down vote accepted

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)
share|improve this answer
Thanks! Please add to remove the damaged file before (rm /etc/bashrc) and restart bash after (source ~/.bash_profile) – Nickolai Leschov Apr 5 '14 at 17:12

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 & fast, but in my humble opinion you are much safer just opening the file in an editor & 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 & move on.

share|improve this answer
Added: I did echo 'export EDITOR=/usr/bin/nano' > /etc/bashrc when I should have written >>. I already did replace the file with the one from /etc/skel/, but I keep getting "Connection to closed.". I guess the file in /etc/skel/ is a template for a "real" .bashrc, rather than an instance of a proper configuration file in itself. Maybe the .bashrc is supposed to contain an endless loop or something? I can only log in via hitting Ctl+C between issuing an ssh command from my computer and the time it kicks me out. By the way, on my system it's /etc/bashrc without a period – Nickolai Leschov Apr 5 '14 at 16:42
Ahhh, okay. A bit of general advice about >> I have edited into my answer. – JakeGould Apr 5 '14 at 19:29

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

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.