-bash:chattr:找不到命令
我正在尝试更改我的 .bash_profile
并且它返回
写入 .bash_profile 时出错权限被拒绝
所以,我使用 chattr -i .bash_profile
使其不可变,它给了我
-bash:chattr:找不到命令。
有人可以帮我解决这个问题吗?
I am trying to change my .bash_profile
and it spits back
error writing to .bash_profile Permission denied
So, I use the chattr -i .bash_profile
to make it immutable and it gives me
-bash: chattr: command not found.
Can someone please help me on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用 Ubuntu 或 Debian,您可以使用
然后再试一次。
If you use Ubuntu or Debian you can use
Then you try again.
为什么您从该消息中假设该文件是“不可变的”并且需要您执行
chattr -i
?您没有提供足够的信息来说明问题所在,但我的第一个想法是 1)该文件不属于您(可能是在 su'ed 或 sudo'ed 时创建的),或者 2)权限不不允许您写入文件。
如果您确实是所有者(或者可以执行
chown
来使自己成为所有者,假设这是适当的),请尝试对其执行chmod u+w
。Why do you assume, from that message, that the file is "immutable" and needs you to do a
chattr -i
?You haven't given quite enough information to tell what the problem is, but my first thoughts are that 1) the file is not owned by you (created while su'ed or sudo'ed, perhaps), or 2) the permissions don't allow you to write to the file.
If you are indeed the owner (or can do a
chown
to make yourself the owner, assuming that's appropriate) try doingchmod u+w
on it.这将安装
chattr
:apt-get install e2fsprogs
This will install
chattr
:apt-get install e2fsprogs
好吧,我不确定这是否有帮助,因为正在使用什么操作系统的问题没有得到解答,但我在 FreeBSD 中遇到了类似的问题,其中手册页似乎暗示 FreeBSD 支持 chattr 以及 lsattr 但是当您尝试使用任何一个都会收到“命令未找到”错误,这使得它有点令人困惑。
经过一番广泛的挖掘后,我发现了以下内容,这也可能解决这个问题,或者如果不能至少指出正确的方向,
FreeBSD 通过使用名为 Immutable 的特殊位来打开它,您可以执行以下命令来提供写保护:
要测试是否设置了此标志,请执行以下命令:
这会得到以下结果:
要清除或删除文件不可变位,请执行以下操作:
现在可以删除文件
注意:只能设置此不可变标志由 root 用户执行。
此外 chflags 支持一些其他有趣的标志:
注意:输入“否”因此
,如果您无权访问 chattr 和 lsattr ,那么可能是因为它们使用此方法来执行相同的操作。
PS 如果文件已设为不可变或仅追加,则在文件属性更改之前无法删除该文件。不确定其他设置,但这是关于这两个设置的信息。
Okay I am not sure if this will help since the question of what OS was being used was not answered but I encountered a similar issue working within FreeBSD where the Man Pages seem to imply that FreeBSD supports chattr as well as lsattr however when you try to use either one you get the "command not found" error which makes it a bit confusing.
Still after some extensive digging I found the following and this may solve this problem as well or if not at least perhaps point someone in the right direction
FreeBSD offers write protection by using the special bit called Immutable to turn this on you do the following command:
To test to see if this flag is set you do the following command:
Which gets you the following results:
To clear or remove the file Immutable bit you do the following:
Now the file can be deleted
Note: This Immutable flag can only be set by the root user.
Further chflags supports a few other interesting flags:
Note: Putting a "no" before an option causes the flag to be turned off
So if you do not have access to chattr and lsattr then perhaps it is because they use this methodology to do the same thing.
P.S. If a file has been made Immutable or Append-Only it cannot be deleted until that attribute of the file has been changed. Not sure about any of the other settings but that was the information stated about these two.
“权限被拒绝”错误可能是由于您在经典 UNIX 权限模型下没有足够的权限而导致的。
不变性(以及这个特定的文件属性系统)是 Linux 的特性。 Chattr 不包含在 coreutils 中,因此您可能需要单独安装它(如何执行此操作取决于您的 Linux 发行版)。
另外,chattr -i 会删除不变性标志,而不是设置它。
That "Permission denied"-error might result from you not having sufficient permissions under the classical UNIX permission model.
Immutability (and this specific file-attribute-system) is a Linux specificity. Chattr is not contained in coreutils, so you might need to install it seperately (how to do this depends on your Linux distribution).
Also,
chattr -i
will remove the immutability-flag, not set it.