← 返回命令列表

Linux command

setfattr 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Example

setfattr -n user.[attribute_name] -v "[value]" [path/to/file]

Example

setfattr -n user.[attribute_name] [path/to/file]

Remove

setfattr -x user.[attribute_name] [path/to/file]

Restore

setfattr --restore=[dumpfile]

Example

setfattr -h -n user.[attribute_name] -v "[value]" [path/to/symlink]

说明

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.

参数

-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

FAQ

What is the setfattr command used for?

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.

How do I run a basic setfattr example?

Run `setfattr -n user.[attribute_name] -v "[value]" [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -n, --name _name_ do in setfattr?

Specifies the name of the extended attribute to set