chattr

パーミッション

書き方

sudo chattr +i [file]

ファイルシステム水準の属性を付けます。+i を掛けると root でも先に外さなければ変更できず、Linux の ext4、xfs、btrfs でしか働きません。

よく使うオプション

オプション意味
+iImmutable: not even root may change or delete it until -i
-iClear the immutable flag so the file can be edited again
+aAppend only, which suits a log file
+ADo not update the access time on reads
-RApply through a whole tree
lsattrThe companion command that shows which flags are set

sudo chattr +i /etc/resolv.conf

Stops anything from overwriting the file.

lsattr /etc/resolv.conf

Shows the i in the flag list.

sudo chattr -i /etc/resolv.conf

Removes it again so you can edit.

数字モードと記号モードは同じものを指します。755 と u=rwx,go=rx は同じ意味です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. chattr は何をしますか。

ファイルシステム水準の属性を付けます。+i を掛けると root でも先に外さなければ変更できず、Linux の ext4、xfs、btrfs でしか働きません。

Q. どう打ちますか。

sudo chattr +i [file] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man chattr にあります。このコマンドはパーミッションの仲間です。

関連するコマンド

man ページ: man chattr