LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

setfattr

Set extended attributes on files

TLDR

Set a user-defined attribute on a file
$ setfattr -n user.[attribute_name] -v "[value]" [path/to/file]
copy
Set an attribute name without a value
$ setfattr -n user.[attribute_name] [path/to/file]
copy
Remove a specific attribute from a file
$ setfattr -x user.[attribute_name] [path/to/file]
copy
Restore attributes from a dump file
$ setfattr --restore=[dumpfile]
copy
Modify attributes on a symbolic link itself (not target)
$ setfattr -h -n user.[attribute_name] -v "[value]" [path/to/symlink]
copy

SYNOPSIS

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

DESCRIPTION

setfattr sets or modifies extended attributes on files and directories. Extended attributes are name-value pairs permanently associated with files, similar to environment variables but stored in the filesystem. Attribute names must be in the format namespace.name where namespace is typically user, system, security, or trusted.The user namespace is available to regular users for arbitrary data storage. System namespaces require appropriate capabilities or root privileges. Values can be specified as quoted strings with escape sequences, hexadecimal with 0x prefix, or base64 with 0s prefix.

PARAMETERS

-n, --name name

Specifies the name of the extended attribute to set
-v, --value value
Specifies the new value of the extended attribute. Value can be a string, hex (0x prefix), or base64 (0s prefix)
-x, --remove name
Remove the named extended attribute entirely
-h, --no-dereference
Do not follow symbolic links; operate on the link itself
--restore file
Restore extended attributes from a file created by getfattr --dump
--raw
Do not decode the attribute value
--version
Print version and exit
--help
Print help message

INSTALL

sudo apt install attr
copy
sudo dnf install attr
copy
sudo pacman -S attr
copy
sudo apk add attr
copy
sudo zypper install attr
copy
brew install attr
copy
nix profile install nixpkgs#attr
copy

CAVEATS

Not all filesystems support extended attributes; common supported filesystems include ext2/3/4, XFS, Btrfs, and JFS. The user namespace may be disabled on some mount configurations. Attribute names have a maximum length of 255 bytes. Total attribute storage per file is filesystem-dependent (often 4KB-64KB).

HISTORY

Extended attributes support was added to Linux kernel 2.4 and became fully integrated in 2.6. The setfattr command is part of the attr package, developed as part of the XFS project at SGI and later adopted for general Linux filesystem use.

SEE ALSO

getfattr(1), attr(1), setfacl(1), getfacl(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid