Extended attributes

Related articles
File permissions and attributes
Capabilities
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.
Warning
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
User extended attributes can be used to store arbitrary information about a file. To create one:
$ setfattr --name=user.checksum --value="3baf9ebce4c664ca8d9e5f6314fb47fb" file.txt
Use getfattr to display extended attributes:
$ getfattr --encoding=text --dump file.txt
# file: file.txt
user.checksum="3baf9ebce4c664ca8d9e5f6314fb47fb"
To remove an extended attribute:
$ setfattr --remove=user.checksum file.txt
To find files with certain extended attributes use
rawhide
AUR
:
$ rh
/path/to/dir
'"
XATTR_REGEX
".reea'
Some other user extended attributes 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 extended attributes 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
user.xdg.tags
is not part of the official standard, but it has become a "de facto" standard as several popular programs have implemented support for it (see
#Software
). It is implemented as a
CSV
list of user-specified tags for each file.
Preserving extended attributes
Command
Preserves by default?/Required flag
cp
--archive
/
--preserve=all
/
--preserve=xattr
mv
Yes
1
tar
--xattrs
for creation and
--xattrs-include='*'
for extraction
bsdtar
-p
for extraction
rsync
-X, --xattrs
cpio
No
gzip
No
pax
No
syncthing
by enabling
syncXattrs
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]
Just like you should do for any other data you do not want to lose, you should make regular
backups
of your extended attributes. To make a full backup of the extended attributes of all files in the current directory (recursively):
$ getfattr --dump --recursive . > backup.txt
To restore a backup:
$ setfattr --restore=backup.txt
Support
File systems
All major Linux
file systems
including
Ext4
,
Btrfs
,
ZFS
, and
XFS
support extended attributes. The kernel allows to have extended attribute names of up to 255 bytes and values of up to 64 KiB, but
Ext4
and
Btrfs
might impose smaller limits, requiring extended attributes 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 Alternative Data Streams to extended attributes in FUSE.
NFS
supports extended attributes
since Linux 5.9
.
Software
Application
Supported extended attributes
Notes
baloo
user.xdg.tags
user.baloo.rating
caja
Yes
Supported by caja-xattr-tags and caja.eiciel extensions.
Chromium
No
Used to support referrer and URL, but was disabled due to privacy and security concerns. See also
CVE-2018-20483
.
brave-bin
AUR
No
CURL
user.xdg.origin.url
user.xdg.referrer.url
Enabled with
--xattr
flag.
Dolphin
user.baloo.rating
user.xdg.comment
user.xdg.tags
user.kde.fm.viewproperties#1
Dolphin provides comprehensive support for file tagging, including the ability to add tags to files through the context menu, and support for searching by file tags. Tags are stored as CSV in the
user.xdg.tags
attribute. See also
Dolphin#File tagging
.
[2]
,
[3]
Dropbox
user.com.dropbox.attributes
emacs-vm
No
Resets mbox xattrs.
Epiphany
No
Exiftool
No
fd
No
findutils
No
Firefox
No
gallery-dl
AUR
No
Gwenview
user.xdg.tags
kfind
No
konqueror
No
kio
[4]
Nautilus
No
Full extended file attributes support can be added by the Nautilus extension from
eiciel
AUR
.
rclone
No
recoll
user.xdg.tags
tagspaces
AUR
No
tmsu
AUR
No
Thunar
No
youtube-dl
AUR
,
yt-dlp
user.xdg.referrer.url
user.dublincore.title
user.dublincore.date
user.dublincore.description
user.dublincore.contributor
user.dublincore.format
Enabled with
--xattrs
flag.
Wget
user.xdg.origin.url
user.xdg.referrer.url
Enabled with
--xattrs
flag.
webkit
No
Other tagging systems
It might not be possible to use extended attributes due to lack of support of either the file system or software. For this reason, many media formats store metadata included in the file format that can be viewed using programs like
Exiftool
or more specified ones like
id3
AUR
for audio.
For all files:
Exiftool
For audio:
Audio tag editors
For video:
ffprobe(1)
from
FFmpeg
gvfs
Another filesystem-independent workaround is Gnome virtual filesystem:
gvfs
which is used to store metadata (gvfsd-metadata). For example, Firefox
stores metadata
this way and can be viewed with:
$ gio info --attributes=metadata::
downloaded.html
Other programs that use this approach include:
Thunar
: to save file color highlights.
See also
XDG guidelines for extended attributes
wikipedia:Extended file attributes#Linux
Extended attributes: the good, the not so good, the bad.