← 返回命令列表

Linux command

attr 命令

文件

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

常用示例

Set an extended attribute on a file

attr -s [attribute_name] -V [value] [path/to/file]

Get the value of an extended attribute

attr -g [attribute_name] [path/to/file]

Remove an extended attribute

attr -r [attribute_name] [path/to/file]

List all extended attributes on a file

attr -l [path/to/file]

Set attribute in the user namespace

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

Get all attributes with getfattr

getfattr -d [path/to/file]

说明

attr manipulates extended attributes on filesystem objects. Extended attributes are name-value pairs permanently associated with files and directories, providing metadata storage beyond traditional Unix permissions. Attributes exist in namespaces: user for arbitrary user data, system for OS features like ACLs, security for SELinux labels, and trusted for privileged applications. The attr command primarily works with the user namespace. Extended attributes persist across copy and backup operations when tools support them. Common uses include storing file metadata, checksums, capabilities, and application-specific data without modifying file content. The related commands getfattr and setfattr provide more detailed control and are preferred for scripting.

参数

-s _attrname_
Set the named attribute.
-g _attrname_
Get and display the value of the named attribute.
-r _attrname_
Remove the named attribute.
-l
List all extended attributes on the file.
-V _attrvalue_
Specify the value when setting an attribute.
-L
Follow symbolic links.
-R
Operate on attributes in the root namespace (requires privileges).
-S
Operate on attributes in the security namespace.
-q
Quiet mode; suppress most error messages.

FAQ

What is the attr command used for?

attr manipulates extended attributes on filesystem objects. Extended attributes are name-value pairs permanently associated with files and directories, providing metadata storage beyond traditional Unix permissions. Attributes exist in namespaces: user for arbitrary user data, system for OS features like ACLs, security for SELinux labels, and trusted for privileged applications. The attr command primarily works with the user namespace. Extended attributes persist across copy and backup operations when tools support them. Common uses include storing file metadata, checksums, capabilities, and application-specific data without modifying file content. The related commands getfattr and setfattr provide more detailed control and are preferred for scripting.

How do I run a basic attr example?

Run `attr -s [attribute_name] -V [value] [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -s _attrname_ do in attr?

Set the named attribute.