chattr
권한·소유
쓰는 꼴
sudo chattr +i [file]파일시스템 수준의 속성을 붙입니다. +i를 걸면 root도 먼저 풀지 않고는 고칠 수 없고, 리눅스의 ext4, xfs, btrfs에서만 되며 macOS에는 없습니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| +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도 먼저 풀지 않고는 고칠 수 없고, 리눅스의 ext4, xfs, btrfs에서만 되며 macOS에는 없습니다.
Q. 어떻게 치나요?
sudo chattr +i [file] — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 6개입니다. 전체 목록은 man chattr에 있습니다. 이 명령은 권한·소유 갈래입니다.
같이 보는 명령
man 페이지: man chattr