In Ubuntu 13.10, for the default setting, the following command in Terminal
user@host:~/path$ sudo su
results in entering an prompt
root@host:/home/user/path#
And this command
user@host:~/path$ sudo bash
enters prompt
root@host:~/path#
Is this means a different between those two commands to be that ~
have different meaning?
Usually I use sudo
only. But sometimes it is not enough. For example if I wanted to write a command that modifies some file with cat >> file <<EOF
, and the file is only writeable for root
, I have to either use sudo su
or sudo bash
(assume bash
is your preferred shell). But the above example seems to show that use sudo bash
is better because the operation environment is more like the previous one. Is this the case? What else are different between those commands?
sudo tee
for redirection withsudo
rights.ls > out
, but not for two way redirections as in my case. So can you or @DanielAndersson show me how to usesudo tee
in this case?~
represents your$HOME
directory.cat <<EOF | sudo tee -a file
, followed by content and a newEOF
. Your order works as well. Also, the FAQ linked by @AvinashRaj explains the difference insudo su
andsudo bash
further down: Special notes on sudo and shells