Mac @扩展属性

https://mackuba.eu/2008/06/30/ls-on-mac-and-extended-file-attributes/

Yesterday while I was working in the terminal I noticed something unusual about the results of “ls -al” command:

Results from 'ls -al' command including at symbols (-rw-r--r--@)

What are those symbols? I googled for “mac ls at sign”, but most of the results told me that “@” means “symbolic link”. Well, all those files can’t be symbolic links, I’m pretty sure of that. So what are they?

I found the answer in a mail on Apple mailing list. It seems that the @ symbol means that the file has something called “extended attributes”. The attributes are a kind of metadata about the file stored in a special place in the HFS filesystem, not visible during normal browsing. As I learned from a Wikipedia page, most of popular filesystems support such metadata – although I’ve never heard such thing existed in Windows or Linux… The mail also said that apart from “@”, files can have “+” symbol, which means that they have non-standard permissions set using some kind of ACLs.

The mail explained that you can print that metadata by adding a –@ option to ls. I did that, and learned that some of the files had an attribute “com.apple.TextEncoding”, and some others – “com.apple.quarantine”. It’s easy to guess what TextEncoding is for, but quarantine? WTF?

Again, a quick Google search solved the mystery – the quarantine tag is what causes those messages “xxx is an application which was downloaded from the Internet. Are you sure you want to open it?” that I get when I run an application for the first time. Every file (not only applications, it seems) that is downloaded from the Internet is marked with this quarantine metadata tag. When the user confirms that he wants to open the file, the tag is removed and the popup doesn’t appear again.

There is a command line utility for accessing and managing that metadata, named xattr. It can print file’s metadata attributes and their values, modify attributes and remove them, like this:

$ xattr macruby-interview.html
com.apple.quarantine
$ xattr -l macruby-interview.html
com.apple.quarantine: 0000;485e5e65;Firefox;|org.mozilla.firefox
$ xattr -w pl.psionides foo macruby-interview.html
$ xattr macruby-interview.html
com.apple.quarantine
pl.psionides
$ xattr -l macruby-interview.html
com.apple.quarantine: 0000;485e5e65;Firefox;|org.mozilla.firefox
pl.psionides: foo
$ xattr -d pl.psionides macruby-interview.html
$ xattr -d com.apple.quarantine macruby-interview.html
$ xattr macruby-interview.html
$ ls -l macruby-interview.html
-rw-r--r-- 1 psionides staff 40066 22 cze 16:15 macruby-interview.html

As you can see, the metadata store not only the information that a file was downloaded from the Internet, but also how it was downloaded (using Firefox), and I think also when it was downloaded (the hex value). The -d option can be useful if MacOSX for some reason forgets to remove the quarantine attribute, which – as I’ve read – can happen sometimes.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值