2010. 11. 12. 08:56

Ubuntu/Linux File 속성(Attribute) 변경하기

Linux에서 file과 directory는 read, write 그리고 execute 권한이 있는데, 이는 user, group, other와 연계되어 있습니다. 그리고 역시 속성(attribute)이 있는데, 이는 특정 file system type 별로 file과 directory에 할당되어 있습니다.

ext2와 ext3에 있는 file은 선택하여 사용할 수 있는 특별한 attribute가 있습니다. lsattr 명령으로 이러한 attribute를 나열할 수 있습니다. 대부분의 속성은 모호하고 디폴트로 결정되어 있지 않습니다. 다음의 예를 확인해 보십시요.

$ lsattr /etc/host*
-----------------e- /etc/host.conf
-----------------e- /etc/hostname
-----------------e- /etc/hosts
-----------------e- /etc/hosts.allow
-----------------e- /etc/hosts.deny
$ lsattr -aR /tmp/ | less
...
-----------------e- /tmp/.X11-unix

/tmp/.X11-unix:
-----------------e- /tmp/.X11-unix/..
-----------------e- /tmp/.X11-unix/.

-----------------e- /tmp/mynullfile
-----------------e- /tmp/new
...


ext2/ext3에서 설정된 attribute를 표현해 줍니다. 개별 속성은 다음과 같습니다.

  • a : append only
  • c : compressed
  • d : no dump
  • i : immutable
  • j : data jouralling
  • s : secure deletion
  • t : no tail-merging
  • u : undeletable
  • A : no atime updates
  • D : synchronous directory updates
  • S : synchronous updates
  • T : top of directory hierarchy

이러한 속성을 변경하기 위해, chattr 명령을 이용하며 그 예는 다음과 같습니다.

$ sudo chattr +i whatever.iso
$ sudo chattr +A -R /home/greenfish/images/*
$ sudo chattr +d ubuntu-7.04-desktop.i386.iso
$ lsattr whatever.iso /home/greenfish/images/* ubuntu-7.04-desktop.i386.iso
----i-------- whatever.iso
-------A----- /home/greenfish/images/einstein.jpg
-------A----- /home/greenfish/images/goth.jpg
------d------ ubuntu-7.04-desktop.i386.iso

위 예에서와 같이, +i 옵션은 immutable attribute를 추가하는 것으로, 삭제/이름변경/변경/link 생성등이 불가능해 집니다. 이는 file에 변경을 주지 않겠다라는 뜻힙니다(물론 root user도 i attribute가 없어야만 가능합니다.). 이는 ststem file을 보호하는데 사용할 수 있습니다.

-R 옵션은 recursive로, +A과 함께 설정되어 있습니다. 이는 image directory와 그 하부 directory를 access 시간(atime) 변경을 하지 않겠다라는 뜻입니다. A attribute의 설정은 노트북이나 Flash drive의 disk I/O를 절약해 줄 수 있습니다. 만약 ext2/ext3 file system에 dump 명령을 사용한다면, +d 옵션은 백업을 하지 않게 됩니다. 위 경우 큰 사이즈의 ISO 파일을 백업하지 않도록 명령을 한 것입니다.

attribute의 제거는 - 옵션을 붙이면 됩니다.