sudo open -e~/.bash_profile Permission denied mac

Far*_*enP 6 permissions macos sudo path .bash-profile

我正在尝试编辑bash_profile文件,通过我的mac机器上的以下命令添加到我的sdk的路径.sudo touch~/.bash_profile; 打开-e~/.bash_profile

它在TextEdit中打开文件,但不允许我编辑它.虽然我在运行上述命令时已经给出了超级用户权限和密码.当我尝试编辑它时它会给我以下消息.

"您不拥有".bash_profile"文件,并且无权写入该文件.您可以复制此文档并编辑副本.只有副本才会包含您的更改." 我是mac的新手.所以请详细说明你的答案.

Som*_*ude 12

问题是该文件不归您的用户所有,而是由root.您需要将文件的所有者更改为您的用户,然后您可以打开并编辑该文件,而无需使用sudo:

sudo chown farheen ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

这将作为超级用户将文件的所有者更改回给您.

  • 须藤打开 -e ~/.bash_profile; 我这样做了,但仍然收到相同的错误消息。我想要做的就是编辑这个文件。 (2认同)

Hit*_*esh 7

对于 Mac 用户 Catalina,

.bash_profile未打开,他们需要授予编辑此文件的权限。您可以通过以下步骤来实现

1)打开终端并输入以下命令:sudo chown iMac ~/.bash_profile

sudo chown {your username} ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

2)在终端中打开编辑器,这里我使用nano

nano .bash_profile
Run Code Online (Sandbox Code Playgroud)

3)编辑你想要的文字。

4) 要保存所做的更改,请按Ctrl + O

5) 要退出 nano,请按Ctrl + X

6)最后要加载您的更改,请输入以下命令

source .bash_profile
Run Code Online (Sandbox Code Playgroud)