Trying to modify /etc/bash.bashrc I get an error:

$ echo "my edit" >> /etc/bash.bashrc
bash: /etc/bash.bashrc: Permission denied

ls -ll /etc/bash.bashrc shows:

-rw-r--r-- 1 root root 1975 2011-05-18 19:54 /etc/bash.bashrc

How could I modify /etc/bash.bashrc ?

  • 4
    Also, you know you can just edit ~/.bashrc? You probably do, but just making sure. lol – Matt Oct 28 '11 at 3:44
  • 1
    Also see stackoverflow.com/questions/82256/… – belacqua Oct 28 '11 at 5:35
  • sudo $EDITOR /etc/bashrc. You can set $EDITOR in your .bashrc as well (with - e.g. - export EDITOR=vim). Or you can simply run (e.g.) sudo atom /etc/bashrc which will use the atom editor, or you can replace "atom" with whatever. – dylnmc Oct 1 '16 at 16:40

You need superuser permissions to edit the file.

To become the superuser, type in sudo -s then enter your password. After you log in, then try your command, and it will work.

  • 7
    sudo chmod 777 /etc/bash.bashrc: Terrible idea. – ændrük Oct 28 '11 at 3:52
  • They asked, I answered. – Matt Oct 28 '11 at 3:54
  • 5
    No one asked you how to create system-wide security holes. That was your own suggestion. The responsible thing for you to do would have been to explain how to modify the contents of the file in accordance with Ubuntu's documented best practices for privilege elevation. – ændrük Oct 28 '11 at 4:13
  • I have edited my answer. – Matt Oct 28 '11 at 4:51
  • Can't see any reason on chmod'ing a /etc/bash.bashrc. – Andrejs Cainikovs May 18 '12 at 8:06
sudo bash -c "echo 'text' >> /etc/bashrc"

Don't change the owner. Don't chmod it. Just use sudo. Open it with sudoedit if you need to do complicated things.

By the way, you can make changes for one user by just editing ~/.bashrc without requiring any special permissions.

  • Clean and mean. – Andrejs Cainikovs May 18 '12 at 8:07
  • su -c "echo 'text'" >> /etc/bashrc ^.^ – dylnmc Oct 1 '16 at 16:37

You've probably discovered by now that there are many ways to do this. But I think this one is the most elegant of all. (It often involves the least typing, too, when everything is said and done.)

echo "my edit" | sudo tee -a /etc/bash.bashrc

See man tee if you're interested in the technical details of how this works.

In general:

  • To do the work of echo some-text > some-file as root, run:

    echo some-text | sudo tee some-file
  • To do the work of echo some-text >> some-file as root, run:

    echo some-text | sudo tee -a some-file
sudo nano /etc/bash.bashrc

Do the changes you want. Save it (Ctrl+X) and confirm with y and Enter.

sudo echo "my edit" >> /etc/bash.bashrc
  • 7
    This does not work. You are echoing as root.. but the regular user is doing the appending. – Matt Oct 28 '11 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.