SETFATTR(1)

๐Ÿ’… setfattr โ€” bestie's guide to setting extended attributes

okay so this is from the File Utilities corner of the manual, and it's called setfattr (short for "set file attributes", but the extended kind, iykyk). It lives in the Extended Attributes section and honestly? It's iconic. Let's get into it.


โœจ NAME โœจ

setfattr โ€” set extended attributes of filesystem objects

Like. You're attaching little extra metadata nametags to your files. That's the whole vibe. ๐ŸŽ€


๐ŸŒธ SYNOPSIS ๐ŸŒธ

setfattr [-h] -n name [-v value] pathname...
setfattr [-h] -x name pathname...
setfattr [-hP] --restore=file

Three modes, bestie: set a thing, remove a thing, or restore a whole pile of things from a file. Pick your fighter. ๐Ÿ’–


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

The setfattr command associates a new value with an extended attribute name for each specified file.

That's it. That's the job. You give it a name, you give it a value, you point it at files, and it goes and does the thing. no cap. โœจ


๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

  • -n name, --name=name โ€” Specifies the name of the extended attribute to set. You gotta have this one, it's the whole point. ๐Ÿซถ
  • -v value, --value=value โ€” Specifies the new value of the extended attribute. There are three methods available for encoding the value, and they are lowkey a whole personality test:
    • If the given string is enclosed in double quotes, the inner string is treated as text. In that case, backslashes and double quotes have special meanings and need to be escaped by a preceding backslash. Any control characters can be encoded as a backslash followed by three digits as its ASCII code in octal.
    • If the given string begins with 0x or 0X, it expresses a hexadecimal number.
    • If the given string begins with 0s or 0S, base64 encoding is expected.

Also see the --encoding option of getfattr(1). (Sibling energy. They're a matched set. ๐Ÿ’•)

  • -x name, --remove=name โ€” Remove the named extended attribute entirely. Bye bye, attribute. not me being emotional about it ๐Ÿ˜ญ
  • -h, --no-dereference โ€” Do not follow symlinks. If pathname is a symbolic link, it is not followed, but is instead modified itself. It said "I'm not chasing that link, I'm touching the link directly." main character energy fr fr.
  • -P, --physical โ€” Do not traverse symbolic links in pathnames during a restore. Can be combined with option -h. Stack 'em, bestie. ๐Ÿ’…
  • --restore=file โ€” Restores extended attributes from file. The file must be in the format generated by the getfattr command with the --dump option. If a dash (-) is given as the file name, setfattr reads from standard input. Very "plug me into a pipe" of it. ๐ŸŒˆ
  • --raw โ€” Do not decode the attribute value. Can be used to set values obtained with getfattr --only-values. Raw as in "no filter, no makeup, just the bytes." ๐Ÿ“
  • --version โ€” Print the version of setfattr and exit. Slay, but make it brief. โญ
  • --help โ€” Print help explaining the command line options. Your bestie when you forget what -P does (it's the symlink one, you're welcome). ๐Ÿ™ˆ
  • -- โ€” End of command line options. All remaining parameters are interpreted as file names, even if they start with a dash character. This is the escape hatch for files with chaotic names. ๐Ÿ’€

๐Ÿงš EXAMPLES ๐Ÿงš

Add extended attribute to user namespace:

$ setfattr -n user.foo -v bar file.txt

To add md5sum of the file as an extended attribute:

# setfattr -n trusted.md5sum -v d41d8cd98f00b204e00998ecf8427e file.txt
Note the # on the second one, bestie โ€” that's root territory. The trusted. namespace doesn't play around. ๐Ÿ‘‘

๐Ÿ’œ AUTHOR ๐Ÿ’œ

Andreas Gruenbacher, <andreas.gruenbacher@gmail.com> and the SGI XFS development team, <linux-xfs@oss.sgi.com>.

Please send your bug reports or comments to <https://savannah.nongnu.org/bugs/?group=attr> or <acl-devel@nongnu.org>.

Legends, honestly. Respect the architects. ๐Ÿซถ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

getfattr(1), xattr(7)

(the duo + the lore page. read all three, iykyk) ๐Ÿฆ‹


and that's the whole page, bestie!! this one's from Dec 2001, filed under Extended Attributes, and the manual name on the tin is SETFATTR(1) โ€” go forth and tag your files, you absolute icon โœจ๐Ÿ’–๐ŸŽ€

๐Ÿ“ฆ where this page comes from