【问题标题】:sudo open -e ~/.bash_profile Permission denied macsudo open -e ~/.bash_profile 权限被拒绝 mac
【发布时间】:2015-03-19 20:57:52
【问题描述】:

我正在尝试编辑 bash_profile 文件以通过我的 mac 机器上的以下命令添加到我的 sdk 的路径。 须藤触摸〜/ .bash_profile;打开 -e ~/.bash_profile

它在 TextEdit 中打开文件,但不允许我编辑它。尽管我在运行上述命令时已授予超级用户权限和密码。当我尝试编辑它时,它会给我以下消息。

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

【问题讨论】:

  • 顺便说一下,你不应该以超级用户创建文件,~/路径是你自己的主目录,~/.bash_profile文件应该归你所有。
  • 我不想创建这个文件。它已经存在。我只是想编辑它来设置一个 PATH 变量。
  • 那么为什么要使用touch 命令?而且您的用户似乎不是文件的所有者。如果你这样做,例如ls -l ~/.bash_profile 它列出了哪些用户? sudo open -e ~/.bash_profile 也不起作用(应该!)?
  • ls -l ~/.bash_profile 显示如下:-rw-r--r-- 1 根人员 104 Jan 21 17:26 /Users/farheen/.bash_profile
  • OSX open 命令可能会更改用户或其他内容。至于文件,它应该归你所有(farheen)。使用chown 更改它:sudo chown farheen ~/.bash_profile。之后,您应该不需要使用sudo 来编辑它(只需使用open 命令!不要使用sudo touch!)。

标签: macos path permissions sudo .bash-profile


【解决方案1】:

问题在于该文件不属于您的用户,而是属于root。您需要将文件的所有者更改为您的用户,然后您可以在不使用sudo的情况下打开和编辑文件:

sudo chown farheen ~/.bash_profile

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

【讨论】:

  • sudo open -e ~/.bash_profile;我这样做了,我仍然收到相同的错误消息。我要做的就是编辑这个文件。
【解决方案2】:

对于 Mac 用户 Catalina,

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

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

sudo chown {your username} ~/.bash_profile

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

nano .bash_profile

3) 编辑您想要的文本。

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

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

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

source .bash_profile

【讨论】:

    【解决方案3】:

    您可以使用如下方式授予权限并使其成为可执行文件:

    该错误可能意味着“bash_profile”不可执行。如果它在当前目录中,您可以使用 chmod +x bash_profile 使其可执行。

    【讨论】:

      猜你喜欢
      • 2015-11-08
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 2020-11-25
      • 2017-03-01
      • 2012-03-22
      相关资源
      最近更新 更多