2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Linuxでファイルを上書き不可・削除不可にする

Last updated at Posted at 2023-08-07

chattr +i しておくと削除も上書きも追記もできなくなる。
lsattr ファイル名 で属性確認し、
chattr -i で属性削除。

$ touch hoge
$ chattr +i hoge
$ lsattr hoge
----i---------e------- hoge
$ echo aaa > hoge
zsh: 許可されていない操作です: hoge
$ echo aaa >> hoge
zsh: 許可されていない操作です: hoge
$ rm hoge
rm: 'always' を削除できません: 許可されていない操作です
$ chattr -i hoge

i フラグの意味は:

       i      A  file  with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file's metadata can not be modified, and the file can not be opened in write mode.
              Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?