Extended attributes - ArchWiki

Jump to content
From ArchWiki

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 -n user.checksum -v "3baf9ebce4c664ca8d9e5f6314fb47fb" file.txt

Use getfattr to display extended attributes:

    $ getfattr -e text -d file.txt

    # file: file.txt
    user.checksum="3baf9ebce4c664ca8d9e5f6314fb47fb"

To remove an extended attribute:

    $ setfattr -x user.checksum file.txt

To find files with certain extended attributes use rawhideAUR:

    $ 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`

## Preserving extended attributes

Command | Preserves by default?/Required flag
--- | ---
`cp` | `--archive`/`--preserve=all`/`--preserve=xattr`
`mv` | Yes1
`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

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]

## 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 does not currently support extended attributes.

### 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 | No |
CURL |
    user.xdg.origin.url
    user.xdg.referrer.url
| Enabled with `--xattrs` flag.
dolphin |
    user.baloo.rating
    user.xdg.comment
    user.xdg.tags
| [2]
Dropbox | `user.com.dropbox.attributes` |
emacs-vm | No | Resets mbox xattrs.
Epiphany | No |
Exiftool | No |
fd | No |
find | No |
Firefox | No |
gallery-dlAUR | No |
Gwenview | `user.xdg.tags` |
kfind | No |
konqueror | No |
kio | [3] |
Nautilus | No |
recoll | `user.xdg.tags` |
tagspacesAUR | No |
tmsuAUR | No |
Thunar | No |
youtube-dl, 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 id3AUR for audio.

- For all files: Exiftool
- For audio: Audio tag editors
- For video: ffprobe

### 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.

Category:

- File systems