chattr
パーミッション
書き方
sudo chattr +i [file]ファイルシステム水準の属性を付けます。+i を掛けると root でも先に外さなければ変更できず、Linux の ext4、xfs、btrfs でしか働きません。
よく使うオプション
| オプション | 意味 |
|---|---|
| +i | Immutable: not even root may change or delete it until -i |
| -i | Clear the immutable flag so the file can be edited again |
| +a | Append only, which suits a log file |
| +A | Do not update the access time on reads |
| -R | Apply through a whole tree |
| lsattr | The companion command that shows which flags are set |
例
sudo chattr +i /etc/resolv.confStops anything from overwriting the file.
lsattr /etc/resolv.confShows the i in the flag list.
sudo chattr -i /etc/resolv.confRemoves 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