·터미널 명령어

chattr

권한·소유

쓰는 꼴

sudo chattr +i [file]

파일시스템 수준의 속성을 붙입니다. +i를 걸면 root도 먼저 풀지 않고는 고칠 수 없고, 리눅스의 ext4, xfs, btrfs에서만 되며 macOS에는 없습니다.

자주 쓰는 옵션

옵션
+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도 먼저 풀지 않고는 고칠 수 없고, 리눅스의 ext4, xfs, btrfs에서만 되며 macOS에는 없습니다.

Q. 어떻게 치나요?

sudo chattr +i [file] — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 6개입니다. 전체 목록은 man chattr에 있습니다. 이 명령은 권한·소유 갈래입니다.

같이 보는 명령

man 페이지: man chattr