apr 24
在雪豹下,有时候在往非本地硬盘(比如网络共享或者外挂移动硬盘等)拷贝文件的时候,会发生“不能完成此操作,因为您没有权限访问一些项目”的错误信息。
刚开始碰到的时候,我以为我家文件服务器的 Samba 配置出了问题(因为那几天刚好我做了一点小调整),后来发现和 Samba 没有关系,并且拷贝到外挂移动硬盘或者 U 盘也会有这个错误,但只限于那几个文件。
将出错的文件仔细定位后,发现是一个视频字幕文件,具体做了哪些操作也忘了,在终端下使用 "ls -al" 命令发现该文件的权限位最后多了一个 “@” 符号,类似以下形式:
-rw-r--r--@ 1 dirk staff 62584 somefile.srt
在网上搜搜后,说得最多的是关于隐藏属性的标志,但实际此文件在 Finder 中并没有被隐藏。几番搜索并试验后,发现和 xattr 这个命令相关。
可是,可是,为什么 xattr 没有 man page 呢?为什么?
还好,可以看看 "xattr -h":
[dirk@idesk:~]$ xattr -h
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最终的解决办法是分两步走:
- 首先,使用 "xattr 文件名" 命令看看该文件附加了什么属性,比如我那个字幕文件多了 “com.apple.metadata:kMDItemWhereFroms” 这么一个属性。
- 然后可以使用 xattr 删除此属性,文件就恢复正常了!(如果是多个属性,挨个删除即可)
[dirk@idesk:~]$ xattr -d com.apple.metadata:kMDItemWhereFroms somefile.srt
问题解决,打完收工!!!



No comments yet