拡張属性
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.
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" otherwiseuser.xdg.robots.backup
: "true" if a file is included in backup, "false" otherwiseuser.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 |
- 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:
- Preserved: whether xattrs are preserved when copied or moved.
- Tags: whether tags xattrs are supported.
File manager | Preserved | Tags |
---|---|---|
dolphin | No | |
thunar | Yes | |
caja | Yes1 | |
nautilus |
- 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 |