Extended file attributes
File metadata is stored in extended file attributes (EA) in macOS.
You can see them when listing files in Terminal using command:
ls -la@
For example if your file has a custom Finder icon, you could see listing similar to this one:
-rw-r--r--@ 1 user staff 168142 Oct 1 23:02 file.ext
com.apple.FinderInfo 32
com.apple.ResourceFork 548373
com.apple.metadata:_kMDItemUserTags 42
This means that file has 3 attributes (metadata), including resource fork holding the icon data.
Resource fork
To print resource fork contents of a file, you can use xattr command that allows you to access extended file attributes:
xattr -p com.apple.ResourceFork
however that might not be as useful because resource forks have only binary representation.
You can access that data in different way, through a dedicated filepath filename/..namedfork/rsrc
. Using the example above to copy resource fork into a resource file (data fork):
cp file.ext/..namedfork/rsrc file.rsrc
Many commands have support for handling extended file attributes, for example cp -p
will copy files including access control lists and extended attributes. If you want to copy resource forks separately, then you need to access them individually through ../namedfork/rsrc path.