繁体   English   中英

编辑.bash_profile时拒绝权限

[英]Permission Denied when editing .bash_profile

我还在学习CLI及其中的细节,特别是这个.bash_profile。 我对自己所学到的东西感到不知所措。

无论如何,我可以访问.bash_profile。 如果我执行nano ~/.bash_profile则文件出现,我可以自由编辑。 然后我尝试添加我应该包括的行:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

但是,当我尝试保存文件(或任何.bash_profile)时,我收到以下错误: [ Error writing /home/myname.bash_profile Permission denied ]

虽然你可以使用sudo nano ~/.bash_profile来编辑文件,但我觉得你的.bash_profile需要root来修改它有点奇怪。

如果你试试ls -la ~ | grep bash ls -la ~ | grep bash

-rw-------    1 Greg  staff    8622 27 Jun 16:06 .bash_history
-rw-r--r--    1 Greg  staff    2189 28 Jun 01:24 .bash_profile

你看我的.bash_profile归我所有,Greg,而不是root。 我想你会发现,当你这样做时,你的.bash_profile将归root所有。 这意味着当你想编辑文件时,你需要使用sudo,但我没有。

如果您不想一直使用sudo来修改此文件,则可以更改文件的所有者sudo chown yourusername ~/.bash_profile

现在如果你运行我上面显示的ls命令,你应该看到你的名字作为文件的所有者,而不是root。

您需要root权限才能进行编辑。

使用sudo编辑它或以root身份登录并编辑。

谢谢,

桑迪普。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM