9

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.

0

5 Answers 5

13

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)
1
  • Thanks! Please add to remove the damaged file before (rm /etc/bashrc) and restart bash after (source ~/.bash_profile) Apr 5, 2014 at 17:12
10

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.

2
  • 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 Apr 5, 2014 at 16:42
  • Ahhh, okay. A bit of general advice about >> I have edited into my answer. Apr 5, 2014 at 19:29
1

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

0

3 commands lines to restore bashrc ! you give to us a very usefull answer, especially for a linux beginner like me, I successfully apply it,

mv /etc/bashrc /etc/bashrc.damaged
yum reinstall $(rpm -qf /etc/bashrc)
source ~/.bash_profile

thanks for all

0

Run (you don't need to be root)

dnf download $(rpm -qf /etc/bashrc)

to download the rpm package in the current directory. Then extract the package and move the file where it belongs. This way you don't need to reinstall any package.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .