Strip metadata from files in Snow Leopard

人走茶凉 提交于 2019-12-10 00:58:29

问题


I found the command "mdls" which will show the metadata but I can't see how to delete it.

I want to get rid of the comments "kMDItemFinderComment", "kMDItemWhereFroms" from my files.

Is there a way to do this?


回答1:


I think you're looking for the xattr command, available in Terminal:

xattr -pr com.apple.metadata:kMDItemFinderComment /

that will print all the finder comments for all files on your boot volume. To delete, use the -d switch:

xattr -dr com.apple.metadata:kMDItemFinderComment /

You should test this out on a single file before running it in bulk.

usage: xattr [-l] [-r] [-v] [-x] file [file ...]
       xattr -p [-l] [-r] [-v] [-x] attr_name file [file ...]
       xattr -w [-r] [-v] [-x] attr_name attr_value file [file ...]
       xattr -d [-r] [-v] attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to the string attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
  -h: print this help
  -r: act recursively
  -l: print long format (attr_name: attr_value and hex output has offsets and
      ascii representation)
  -v: also print filename (automatic with -r and with multiple files)
  -x: attr_value is represented as a hex string for input and output



回答2:


You can do this by:

xattr -d com.apple.metadata:kMDItemFinderComment <file>
xattr -d com.apple.metadata:kMDItemWhereFroms <file>

Seems to work for me.




回答3:


The Spotlight comments are also stored in .DS_Store files. If you try adding a comment in Finder's information window and running xattr -d com.apple.metadata:kMDItemFinderComment, the comment will still be shown in Finder, but not by mdls -n kMDItemFinderComment. This would delete both of them:

find . -name .DS_Store -delete
xattr -dr com.apple.metadata:kMDItemFinderComment .


来源:https://stackoverflow.com/questions/1552968/strip-metadata-from-files-in-snow-leopard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!