bash .bashrc:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19742005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.bashrc: Permission denied
提问by srgg6701
I try to work with a project in vagrant.
I have made the command vagrant ssh
, and connected to VM. Now I need to edit .bashrc
file to set path to the source code. But first I couldn't find that file. So I googled and find that the way is call command ~/.bashrc
. But doing this I get message, that I have no access to it:
我尝试在 vagrant 中处理一个项目。我已经发出命令vagrant ssh
,并连接到虚拟机。现在我需要编辑.bashrc
文件来设置源代码的路径。但首先我找不到那个文件。所以我用谷歌搜索,发现方法是 call command ~/.bashrc
。但是这样做我收到消息,我无法访问它:
[vagrant@nupic-vagrant:~]$ ~/.bashrc
-bash: /home/vagrant/.bashrc: Permission denied
So what to do now?
那么现在该怎么办?
UPD.
I can't find the .bashrc file.
When I try to make command ls -a
I get following:
更新。我找不到 .bashrc 文件。当我尝试发出命令时,ls -a
我得到以下信息:
[vagrant@nupic-vagrant:~]$ ls -a
. .bash_logout cleanup.sh sshd.sh .veewee_params
.. .bash_profile minimize.sh vagrant.sh .veewee_version
.bash_history .bashrc .ssh .vbox_version .zsh_profile
[vagrant@nupic-vagrant:~]$ locate .bashrc
/etc/skel/.bashrc
/home/vagrant/.bashrc
/var/chef/backup/etc/skel/.bashrc.chef-20130614181911
/var/chef/backup/home/vagrant/.bashrc.chef-20130614181912
[vagrant@nupic-vagrant:~]$
But only the place where I can find some of those files is the directory where cygwin is installed. Pls, see illustrations, they reflect relations between directories vagrant and cygwin.
但只有我可以找到其中一些文件的地方是安装 cygwin 的目录。请参见插图,它们反映了目录 vagrant 和 cygwin 之间的关系。
回答by gniourf_gniourf
.bashrc
is not meant to be executed but sourced. Try this instead:
.bashrc
不是要执行,而是要采购。试试这个:
. ~/.bashrc
Cheers!
干杯!
回答by Radu R?deanu
If you want to edit that file (or any file in generally), you can't edit it simply writing its name in terminal. You must to use a command to a text editor to do this. For example:
如果您想编辑该文件(或一般情况下的任何文件),您不能简单地在终端中写入其名称来编辑它。您必须使用文本编辑器的命令来执行此操作。例如:
nano ~/.bashrc
or
或者
gedit ~/.bashrc
And in general, for any type of file:
一般来说,对于任何类型的文件:
xdg-open ~/.bashrc
Writing only ~/.bashrc
in terminal, this will try to execute that file, but .bashrc
file is not meant to be an executable file. If you want to execute the code inside of it, you can source it like follow:
仅~/.bashrc
在终端中写入,这将尝试执行该文件,但.bashrc
文件并不意味着是可执行文件。如果你想执行其中的代码,你可以像下面这样获取它:
source ~/.bashrc
or simple:
或简单:
. ~/.bashrc
回答by Radu R?deanu
If you can't access the file and your os is any linux distro or mac os x then either of these commands should work:
如果您无法访问该文件并且您的操作系统是任何 linux 发行版或 mac os x,那么这些命令中的任何一个都应该可以工作:
sudo nano .bashrc
chmod 777 .bashrc
it is worthless
毫无价值
回答by Fergal Byrne
The .bashrc file is in your user home directory (~/.bashrc or ~vagrant/.bashrc both resolve to the same path), inside the VM's filesystem. This file is invisible on the host machine, so you can't use any Windows editors to edit it directly.
.bashrc 文件位于您的用户主目录中(~/.bashrc 或 ~vagrant/.bashrc 都解析为相同的路径),在 VM 的文件系统中。此文件在主机上是不可见的,因此您无法使用任何 Windows 编辑器直接对其进行编辑。
You have two simple choices:
您有两个简单的选择:
Learn how to use a console-based text editor. My favourite is vi (or vim), which takes 15 minutes to learn the basics and is much quicker for simple edits than anything else.
vi .bashrc
Copy .bashrc out to /vagrant (which is a shared directory) and edit it using your Windows editors. Make sure not to save it back with any extensions.
cp .bashrc /vagrant ... edit using your host machine ... cp /vagrant/.bashrc .
了解如何使用基于控制台的文本编辑器。我最喜欢的是 vi(或 vim),它需要 15 分钟来学习基础知识,并且比其他任何东西都快得多。
vi .bashrc
将 .bashrc 复制到 /vagrant(这是一个共享目录)并使用 Windows 编辑器对其进行编辑。确保不要将它与任何扩展一起保存。
cp .bashrc /vagrant ... 使用你的主机编辑 ... cp /vagrant/.bashrc 。
I'd recommend getting to know the command-line based editors. Once you're working inside the VM, it's best to stay there as otherwise you might just get confused.
我建议您了解基于命令行的编辑器。一旦您在 VM 内工作,最好留在那里,否则您可能会感到困惑。
You (the vagrant user) are the owner of your home .bashrc so you do have permissions to edit it.
您(流浪用户)是您的主 .bashrc 的所有者,因此您确实有权编辑它。
Once edited, you can execute it by typing source .bashrc I prefer to logout and in again (there may be more than one file executed on login).
编辑后,您可以通过键入 source .bashrc 来执行它,我更喜欢注销并再次登录(登录时可能会执行多个文件)。