Ubuntu16.04 使用sudo cat EOF 编辑文件,提示Permission denied错误的解决办法
?
一、執行命令報錯
在Ubuntu16.04下,使用如下命令,修改hosts主機文件,居然提示權限錯誤:
catty@node186:~$ sudo cat <<EOF > /etc/hosts
127.0.0.1 localhost
192.168.1.101 master1
192.168.1.102 worker1
192.168.1.103 worker2
192.168.1.104 worker3
EOF
-bash: /etc/hosts: Permission denied
catty@node186:~$
二、解決辦法1
catty@node186:~$ sudo bash -c "cat > /etc/hosts" <<EOF
127.0.0.1 localhost
192.168.1.101 master1
192.168.1.102 worker1
192.168.1.103 worker2
192.168.1.104 worker3
EOF
catty@node186:~$
三、解決辦法2:
catty@node186:~$ sudo tee /etc/hosts >/dev/null <<EOF
127.0.0.1 localhost
192.168.1.101 master1
192.168.1.102 worker1
192.168.1.103 worker2
192.168.1.104 worker3
EOF
catty@node186:~$
?
參考鏈接:
https://superuser.com/questions/340074/bash-permission-denied-issue-when-trying-to-append-to-eof
https://www.iteye.com/topic/1127130
http://www.ebanban.com/?p=677
轉載于:https://www.cnblogs.com/rancher-maomao/p/10146860.html
總結
以上是生活随笔為你收集整理的Ubuntu16.04 使用sudo cat EOF 编辑文件,提示Permission denied错误的解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解题:洛谷2093 JZPFAR
- 下一篇: Editplus的扩展程序的删除