ATTR Linux Command
What is Linux attr Command?
Explanation
attr COMMAND:The attr command is used to set, list or remove extended attributes on XFS filesystem objects. XFS is a Linux filesystem which is NAS devices. That is this command is used to maninpulate on the extended attributes associated with filesystem objects from within shell scripts. The extended attributes implement the ability for a user to attach name:value pairs to objects within the XFS filesystem.
The attr command is used to set, list or remove extended attributes on XFS filesystem objects. XFS is a Linux filesystem which is NAS devices. That is this command is used to maninpulate on the extended attributes associated with filesystem objects from within shell scripts. The extended attributes implement the ability for a user to attach name:value pairs to objects within the XFS filesystem.
SYNTAX:
attr [-LRSq] -s attrname [-V attrvalue] pathname
attr [-LRSq] -g attrname pathname
attr [-LRSq] -r attrname pathname
attr [-LRq] -l pathname
DESCRIPTION:
There are four main operations that attr can perform:
Tag |
Description |
GET |
The -g attrname option tells attr to search the named object and print (to stdout) the value associated with that attribute name. With the -q flag, stdout will be exactly and only the value of the attribute, suitable for storage directly into a file or processing via a piped command. |
LIST |
The -l option tells attr to list the names of all the attributes that are associated with the object, and the number of bytes in the value of each of those attributes. With the -q flag, stdout will be a simple list of only the attribute names, one per line, suitable for input into a script. |
REMOVE |
The -r attrname option tells attr to remove an attribute with the given name from the object if the attribute exists. There is no output on sucessful completion. |
SET/CREATE |
The -s attrname option tells attr to set the named attribute of the object to the value read from stdin. If an attribute with that name already exists, its value will be replaced with this one. If an attribute with that name does not already exist, one will be created with this value. With the -V attrvalue flag, the attribute will be set to have a value of attrvalue and stdin will not be read. With the -q flag, stdout will not be used. Without the -q flag, message showing the attribute name and the entire value will be printed. |
OPTION:
Option |
Description |
-L |
When -L option is given and the named object is a symbolic link, operate on the attributes of the object referenced by the symbolic link. Without this option, operate on the attributes of the symbolic link itself. |
-R |
When the -R option is given and the process has appropriate privileges, operate in the root attribute namespace rather that the USER attribute namespace. |
-S |
The -S option is similar, except it specifies use of the security attribute namespace. |
-q |
When the -q option is given attr will try to keep quiet. It will output error messages (to stderr) but will not print status messages (to stdout). |
EXAMPLE:
- Consider a file test.php, now let's set two attributes name and class for the file as follows:
attr -s "name" -V "class" test.php
The above command will produce the below output:
Attribute "name" set to a 5 byte value for test.php:
class
- Following is an example to list down all the attributes associated with test.php file:
attr -l test.php
The above command will produce the below output:
Attribute "author" has a 8 byte value for test.php
Attribute "name" has a 5 byte value for test.php
- Following is an example to list down only particular attribute:
attr -g "name" test.php
The above command will produce the below output:
Attribute "name" had a 5 byte value for test.php:
class