拡張属性

提供: ArchWiki
2023年8月12日 (土) 10:13時点におけるAshMyzk (トーク | 投稿記録)による版 (英語版から)
ナビゲーションに移動 検索に移動


From xattr(7): "Extended attributes are name:value pairs associated permanently with files and directories". There are four extended attribute classes: security, system, trusted and user.

警告: By default, extended attributes are not preserved by cp, rsync, and other similar programs, see #Preserving extended attributes.

Extended attributes are also used to set Capabilities.

ユーザ拡張属性

User extended attributes can be used to store arbitrary information about a file. To create one:

$ setfattr -n user.checksum -v "3baf9ebce4c664ca8d9e5f6314fb47fb" foo.txt

Use getfattr to display extended attributes:

$ getfattr -d foo.txt
# file: foo.txt
user.checksum="3baf9ebce4c664ca8d9e5f6314fb47fb"

Finally, to remove an extended attribute:

$ setfattr -x user.checksum foo.txt

some other user xattrs include:

  • user.mime_type: helps programs know mimetype and set it with less guesswork.
  • user.charset: used by the Apache httpd module mod_mime_xattr.
  • user.creator: The name of the application that created the file.

XDG also proposes a set of standardized xattrs to be used by programs:

  • user.xdg.comment: supported by Dolphin and other file managers.
  • user.xdg.origin.url: for files downloaded from a url.
  • user.xdg.robots.index: "true" if a file is included in indexing, "false" otherwise
  • user.xdg.robots.backup: "true" if a file is included in backup, "false" otherwise
  • user.xdg.language
  • user.xdg.creator
  • user.xdg.publisher
  • user.xdg.origin.email.subject
  • user.xdg.origin.email.from
  • user.xdg.origin.email.message-id

拡張属性を保持する

Command Required flag
cp --preserve=mode,ownership,timestamps,xattr
mv preserves by default1
tar --xattrs for creation and --xattrs-include='*' for extraction
bsdtar -p for extraction
rsync -X, --xattrs
cpio No
gzip No
pax No
  1. mv silently discards extended attributes when the target file system does not support them.

To preserve extended attributes with text editors you need to configure them to truncate files on saving instead of using rename(2). [1]

サポート

ファイルシステム

All major Linux file systems including ext, btrfs, zfs, xfs, and more support xattrs. The kernel allows to have xattrs names of up to 255 bytes and values of up to 64 KiB, but ext and btrfs might impose smaller limits, requiring xattrs to be within a "filesystem block".

NTFS uses Alternative Data Streams to store user. The mount option user_xattr or streams_interface=xattr should be used by default. However it might not be supported if mount option streams_interface=windows is used. ntfs-3g supports mapping ADS to extended attributes in FUSE.

NFS does not currently support xattrs.

ファイルマネージャ

Legend:

  1. Preserved: whether xattrs are preserved when copied or moved.
  2. Tags: whether tags xattrs are supported.
File manager Preserved Tags
dolphin No
thunar Yes
caja Yes1
nautilus
  1. caja: supported by caja-xattr-tags and caja.eiciel extensions.

プログラム

Application Supported xattrs Supported since Notes
baloo user.xdg.tags
Chromium user.xdg.origin,user.xdg.referrer
CURL
Dropbox user.com.dropbox.attributes
emacs-vm No Resets mbox xattrs.
Gwenview user.xdg.tags
recoll user.xdg.tags
tmsuAUR No
tagspacesAUR No
Wget

参照