Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
3  
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
add comment

5 Answers

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
6  
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
3  
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
show 6 more comments
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
add comment

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
add comment
sudo -s

Now you are a super admin, execute your command.

share|improve this answer
3  
What's a "super admin"? Is this a commonly used term? –  Eliah Kagan Jun 3 '12 at 21:32
add comment
sudo echo "my edit" >> /etc/bash.bashrc
share|improve this answer
6  
This does not work. You are echoing as root.. but the regular user is doing the appending. –  Matt Oct 28 '11 at 3:42
add comment

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.