Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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 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
1  
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 1.2.3.4 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 at 16:42
    
Ahhh, okay. A bit of general advice about >> I have edited into my answer. –  JakeGould Apr 5 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

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

share|improve this answer

Your Answer

 
discard

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.