Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

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 ?

share|improve this question
Also, you know you can just edit ~/.bashrc? You probably do, but just making sure. lol – Matt Oct 28 '11 at 3:44
Also see… – belacqua Oct 28 '11 at 5:35
up vote 4 down vote accepted

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.

share|improve this answer
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
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.

share|improve this answer
Clean and mean. – Andrejs Cainikovs May 18 '12 at 8:07

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
share|improve this answer
sudo -s

Now you are a super admin, execute your command.

share|improve this answer
What's a "super admin"? Is this a commonly used term? – Eliah Kagan Jun 3 '12 at 21:32
sudo echo "my edit" >> /etc/bash.bashrc
share|improve this answer
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 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.