2013-06-28 79 views
7

我仍然在学习CLI及其来龙去脉,尤其是这个.bash_profile。我对我正在学习的东西感到不知所措。权限在编辑.bash_profile时被拒绝

无论如何,我可以访问.bash_profile。如果我做nano ~/.bash_profile那么文件出现,我可以自由编辑。然后我试图addingin我应该包括行:

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

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

回答

-1

您需要root权限才能编辑。

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

谢谢,

Sandeep。

+0

忘记提及我以root身份登录,当我尝试 – simplycoding

+0

更改权限并尝试编辑时。 – Sandeep

+0

同样的错误 – user1735921

6

尽管您可以使用sudo nano ~/.bash_profile来编辑文件,但我觉得您的.bash_profile需要修改根目录有点奇怪。

如果您尝试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是归我,格雷格,没有根。我想你会发现,当你这样做时,你的.bash_profile将由root拥有。这意味着当你想编辑文件时,你需要使用sudo,但是我不这样做。

如果您不希望有使用sudo所有的时间来修改这个文件,你可以,如果你运行ls命令我上面显示更改文件sudo chown yourusername ~/.bash_profile

的主人现在,你应该看到你的名字作为文件的所有者,而不是根。

+0

这绝对是正确的答案。也是一个很好的解释。 – xyclos

+0

@gykaling但我不能看到.bash_profile在ls -la〜| grep bash ..我可以为此做些什么? – sachsure