fsetxattr - Linux


fsetxattr sets extended attributes (xattrs) for files or directories. Xattrs are name-value pairs that can be used to store arbitrary metadata associated with a file or directory.


fsetxattr [-h] [-V] [-e] [-v] [-T] [-n] [-x] [-i] [-a] [-s]
          <name> <value> <file>


  • -h, --help: Display help and usage information.
  • -V, --version: Print version information.
  • -e, --entry: Print xattr entries.
  • -v, --verbose: Verbose output.
  • -T, --trusted: Set trusted xattr.
  • -n, --null: Separate xattr names and values with ‘\0’ instead of spaces.
  • -x, --xattr-file: Read xattrs from a file.
  • -i, --interactive: Prompt for xattr values.
  • -a, --append: Append value to existing xattr.
  • -s <size>, --size <size>: Set xattr size (bytes).


  • Set an xattr named user.name with value John Doe for file myfile:

    fsetxattr user.name "John Doe" myfile
  • Print the value of xattr user.name for file myfile:

    fsetxattr -e user.name myfile
  • Set a trusted xattr named security.level with value topsecret for file myfile:

    fsetxattr -T security.level topsecret myfile

Common Issues

  • Permission denied: Check file permissions and ensure you have write access.
  • Xattr too large: Use -s option to specify the maximum xattr size.
  • Xattr not supported: Not all filesystems support xattrs. Check your filesystem type.


  • Use find with -exec fsetxattr to set xattrs for multiple files.
  • Combine with getfattr to retrieve xattr values.
  • Integrate with backup tools to preserve xattrs during backups.

Related Commands

  • getfattr: Retrieves extended attributes.
  • chattr: Changes file attributes.
  • lsattr: Lists file attributes.