-bash:chattr:找不到命令

发布于 2025-01-04 03:47:02 字数 255 浏览 0 评论 0原文

我正在尝试更改我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

九歌凝 2025-01-11 03:47:02

如果您使用 Ubuntu 或 Debian,您可以使用

apt-get install e2fsprogs

然后再试一次。

If you use Ubuntu or Debian you can use

apt-get install e2fsprogs

Then you try again.

送君千里 2025-01-11 03:47:02

为什么您从该消息中假设该文件是“不可变的”并且需要您执行 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 doing chmod u+w on it.

锦爱 2025-01-11 03:47:02

这将安装 chattrapt-get install e2fsprogs

This will install chattr: apt-get install e2fsprogs

贱人配狗天长地久 2025-01-11 03:47:02

好吧,我不确定这是否有帮助,因为正在使用什么操作系统的问题没有得到解答,但我在 FreeBSD 中遇到了类似的问题,其中手册页似乎暗示 FreeBSD 支持 chattr 以及 lsattr 但是当您尝试使用任何一个都会收到“命令未找到”错误,这使得它有点令人困惑。

经过一番广泛的挖掘后,我发现了以下内容,这也可能解决这个问题,或者如果不能至少指出正确的方向,

FreeBSD 通过使用名为 Immutable 的特殊位来打开它,您可以执行以下命令来提供写保护:

$ chflags schg filename

要测试是否设置了此标志,请执行以下命令:

$ ls -lo filename

这会得到以下结果:

-r--r--r--  1 root  wheel  schwa  12 Nov 16 15:36 filename

要清除或删除文件不可变位,请执行以下操作:

$ chflags noschg filename

现在可以删除文件

注意:只能设置此不可变标志由 root 用户执行。

此外 chflags 支持一些其他有趣的标志:

  • arch :设置存档标志
  • nodump :设置无转储标志
  • sapped :设置系统仅追加标志
  • schg :设置系统不可变标志
  • sunlnk :设置系统不可删除标志
  • uappnd :设置用户仅追加标志
  • uchg :设置用户不可变标志
  • uunlnk :设置用户不可删除标志

注意:输入“否”因此

,如果您无权访问 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:

$ chflags schg filename

To test to see if this flag is set you do the following command:

$ ls -lo filename

Which gets you the following results:

-r--r--r--  1 root  wheel  schwa  12 Nov 16 15:36 filename

To clear or remove the file Immutable bit you do the following:

$ chflags noschg filename

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:

  • arch : Set the Archived flag
  • nodump : Set the No Dump flag
  • sapped : Set the System Append-Only flag
  • schg : Set the System Immutable flag
  • sunlnk : Set the System Undeletable flag
  • uappnd : Set the User Append-Only flag
  • uchg : Set the User Immutable flag
  • uunlnk : Set the User Undeletable flag

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.

旧人九事 2025-01-11 03:47:02

“权限被拒绝”错误可能是由于您在经典 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文