티스토리 뷰

OS

xattr 사용법 (Update:20151117)

kiros33 2016. 5. 16. 20:03

Revision History

2015/04/10 15:07:37 - 최초 작성

2015/11/17 15:18:08 -  다운로드 경로 설정 (다른 파일 참조시) 추가


Reference Page

XATTR(1) BSD General Commands Manual


맥 확장 속성 관리 명령


>>>>> 파일의 전체 확장 속성 확인하는 방법

 

ls 명령어

$ ls -l@
total 12488
-rw-r-----@ 1 kiros33  staff  6390832 Apr 10 10:40 1.pdf
 com.apple.metadata:kMDItemWhereFroms      81 
 com.apple.quarantine      68 


파일 지정

$ xattr -l 1.pdf
com.apple.metadata:kMDItemWhereFroms:
00000000  62 70 6C 69 73 74 30 30 A2 01 02 5F 10 45 68 74  |bplist00..._.Eht|
00000010  74 70 3A 2F 2F 65 74 74 72 65 6E 64 73 2E 65 74  |tp://ettrends.et|
00000020  72 69 2E 72 65 2E 6B 72 2F 65 74 74 72 65 6E 64  |ri.re.kr/ettrend|
00000030  73 2F 64 6F 77 6E 6C 6F 61 64 50 64 66 2E 64 6F  |s/downloadPdf.do|
00000040  3F 70 61 70 65 72 6E 6F 3D 30 39 30 35 30 30 32  |?paperno=0905002|
00000050  30 33 33 5F 10 2B 68 74 74 70 3A 2F 2F 65 74 74  |033_.+http://ett|
00000060  72 65 6E 64 73 2E 65 74 72 69 2E 72 65 2E 6B 72  |rends.etri.re.kr|
00000070  2F 65 74 74 72 65 6E 64 73 2F 6D 61 69 6E 2E 64  |/ettrends/main.d|
00000080  6F 08 0B 53 00 00 00 00 00 00 01 01 00 00 00 00  |o..S............|
00000090  00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00  |................|
000000A0  00 00 00 81                                      |....|
000000a4
com.apple.quarantine: 0001;55272a22;Google Chrome.app;5454A12C-4826-4A87-B3EB-0C5352C4D3C1


>>>>> 다운로드 경로 보기

 

다운로드한 파일의 확장 속성 확인하는 방법

- 값의 저장 방식은 일반 텍스트 방식과 이진 형식이 있고 이진으로 저장된 경우 Hex 형식으로 표시, -x 옵션을 추가하면 텍스트로 저장된 문자열도 Hex 표현식으로 표시

$ xattr -px com.apple.metadata:kMDItemWhereFroms 1.pdf
62 70 6C 69 73 74 30 30 A2 01 02 5F 10 45 68 74
74 70 3A 2F 2F 65 74 74 72 65 6E 64 73 2E 65 74
72 69 2E 72 65 2E 6B 72 2F 65 74 74 72 65 6E 64
73 2F 64 6F 77 6E 6C 6F 61 64 50 64 66 2E 64 6F
3F 70 61 70 65 72 6E 6F 3D 30 39 30 35 30 30 32
30 33 33 5F 10 2B 68 74 74 70 3A 2F 2F 65 74 74
72 65 6E 64 73 2E 65 74 72 69 2E 72 65 2E 6B 72
2F 65 74 74 72 65 6E 64 73 2F 6D 61 69 6E 2E 64
6F 08 0B 53 00 00 00 00 00 00 01 01 00 00 00 00
00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 81


알아볼 수 있게 표시하는 방법

- 이진값을 Hex 표현식으로 바꾸고 다시 plutil 명령으로 xml이나 json 포맷으로 변환  

$ xattr -px com.apple.metadata:kMDItemWhereFroms 1.pdf | xxd -r -p | plutil -convert xml1 -o - -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
 <string>http://ettrends.etri.re.kr/ettrends/downloadPdf.do?paperno=0905002033</string>
 <string>http://ettrends.etri.re.kr/ettrends/main.do</string>
</array>
</plist>
$ xattr -px com.apple.metadata:kMDItemWhereFroms 1.pdf | xxd -r -p | plutil -convert json -o - -
["http:\/\/ettrends.etri.re.kr\/ettrends\/downloadPdf.do?paperno=0905002033","http:\/\/ettrends.etri.re.kr\/ettrends\/main.do"]

>>>> 다운로드 경로 설정 (직접 지정시)
 
파이프로 전달한 Stdout 값을 Stdin 으로 바꿔서 사용하기가 잘 안되더군요... 명령 두번 사용...
  
포맷
echo "
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>파일의다운로드URL(파일)</string>
<string>파일의다운로드URL을제공한페이지URL(게시글)</string>
</array>
</plist>
" | plutil -convert binary1 -o - - | xxd -p -c10240


명령

echo "

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<array>

<string>http://www.mysite.com/folder/1.pdf</string>

</array>

</plist>

" | plutil -convert binary1 -o - - | xxd -p -c10240


실행

$ echo "
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-bash: !DOCTYPE: event not found
> <plist version="1.0">
> <array>
> <string>http://www.mysite.com/folder/1.pdf</string>
> </array>
> </plist>
> " | plutil -convert binary1 -o - - | xxd -p -c10240
62706c6973743030a1015f1022687474703a2f2f7777772e6d79736974652e636f6d2f666f6c6465722f312e706466080a000000000000010100000000000000020000000000000000000000000000002f
$ xattr -wx com.apple.metadata:kMDItemWhereFroms 62706c6973743030a1015f1022687474703a2f2f7777772e6d79736974652e636f6d2f666f6c6465722f312e706466080a000000000000010100000000000000020000000000000000000000000000002f 1.pdf


결과

$ xattr -px com.apple.metadata:kMDItemWhereFroms 1.pdf | xxd -r -p | plutil -convert xml1 -o - -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
 <string>http://www.mysite.com/folder/1.pdf</string>
</array>
</plist>


>>>> 다운로드 경로 설정 (다른 파일 참조시)


$ sudo xattr -wx com.apple.metadata:kMDItemWhereFroms `xattr -px com.apple.metadata:kMDItemWhereFroms "원본.hwp" | xxd -r -p | plutil -convert binary1 -o - - | xxd -p -c10240` "사본.pdf"


>>>> 속성 제거하기


$ xattr -d com.apple.metadata:kMDItemWhereFroms 1.pdf



검색: Macintosh, 매킨토시, Mac, 맥, OS X, xattr, Extended attributes, 확장 속성, Where From, kMDItemWhereFroms, 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함