Skip to content

Instantly share code, notes, and snippets.

@antaz
Last active March 21, 2023 15:45
Show Gist options
  • Select an option

  • Save antaz/a6da9da9fc4bd8c4496443ce1f844793 to your computer and use it in GitHub Desktop.

Select an option

Save antaz/a6da9da9fc4bd8c4496443ce1f844793 to your computer and use it in GitHub Desktop.
Tagging files with Extended Attributes

Tagging files using extended attributes

Extended attributes

As described in xattr(7) extended attributes are name:value pairs associated with each file on the filesystem

Namespaces

in Linux the only supported namespace classes are security, system, trusted and user which is the most general of these.

Setting

The following command sets a user extended attributes of the file foo.txt

setfattr -n user.mime_type -v text/plain foo.txt

Retrieving

To retrieve the previously set extended attribute we use the following command

getfattr -n user.mime_type foo.txt

Tag format

In order to use extended attributes for tagging we first need to specify a format for file tags. The following is a proposed format

‘tag_1:tag_2:…:tag_n’

We separate each tag with colon. Then we can use the name user.tags to set tags with

setfattr -n user.tags -v family photo.jpg

Adding and removing tags

Searching files with tags

References

https://man7.org/linux/man-pages/man7/xattr.7.html

https://www.freedesktop.org/wiki/CommonExtendedAttributes/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment