Trying to modify /etc/bash.bashrc I get an error:
$ echo "my edit" >> /etc/bash.bashrc
bash: /etc/bash.bashrc: Permission deniedls -ll /etc/bash.bashrc shows:
-rw-r--r-- 1 root root 1975 2011-05-18 19:54 /etc/bash.bashrcHow could I modify /etc/bash.bashrc ?
5 Answers
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.
2You 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.
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.bashrcSee 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-fileasroot, run:echo some-text | sudo tee some-fileTo do the work of
echo some-text >> some-fileasroot, run:echo some-text | sudo tee -a some-file
sudo nano /etc/bash.bashrcDo the changes you want. Save it (Ctrl+X) and confirm with y and Enter.
sudo echo "my edit" >> /etc/bash.bashrc 1