finding xattr recursively for symbolic links rather than their target?

118 Views Asked by At

I've been using the following command (in bash terminal) to find the extended attribute com.apple.metadata:kMDItemComment for files/folders on my system.

sudo find "`pwd`" -xattrname com.apple.metadata:kMDItemComment -exec printf %s\\t {} \; -exec mdls -name kMDItemComment -raw {} \; -exec echo \;

However, the results it returns for symbolic links are the KMDItemComment of their target file/folder.

$ sudo find "`pwd`" -xattrname com.apple.metadata:kMDItemComment -exec printf %s\\t {} \; -exec mdls -name kMDItemComment -raw {} \; -exec echo \;
/Users/MM/Desktop/test/test.txt this is a KMDItemComment
$ xattr -pls com.apple.metadata:kMDItemComment /Users/MM/Desktop/test/test.txt
com.apple.metadata:kMDItemComment: ,SYMLINK

Is there some way I can modify this find command to properly display the KMDItemComment xattr for symbolic links instead of displaying the data from their target file/folder?

I tried using xattr -pls instead of the mdls command, but for files that aren't symlinks, the printed data includes all of the hexadecimal data in addition to the ASCII string for the comment (which is a lot of extra lines of info per-file/folder that I don't want in the output, especially if the comments on the files are particularly long).

$ xattr -pls com.apple.metadata:kMDItemComment /Users/MM/Desktop/test/test.txt
com.apple.metadata:kMDItemComment:
00000000  62 70 6C 69 73 74 30 30 5F 10 4B 74 68 69 73 20  |bplist00_.Kthis |
00000010  69 73 20 61 20 4B 4D 44 49 74 65 6D 43 6F 6D 6D  |is a KMDItemComm|
00000020  65 6E 74 20 77 72 69 74 74 65 6E 20 77 69 74 68  |ent written with|
00000030  20 74 68 65 20 4D 65 74 61 6D 65 72 20 61 70 70  | the Metamer app|
00000040  20 66 72 6F 6D 20 65 63 6C 65 63 74 69 63 6C 69  | from eclecticli|
00000050  67 68 74 2E 63 6F 08 00 00 00 00 00 00 01 01 00  |ght.co..........|
00000060  00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 56                             |......V|
00000077
0

There are 0 best solutions below