setfattr 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

setfattr 命令安装:


-bash/zsh: setfattr command not found

#Debian
apt-get install attr

#Ubuntu
apt-get install attr

#Alpine
apk add attr

#Arch Linux
pacman -S attr

#Kali Linux
apt-get install attr

#CentOS
yum install attr

#Fedora
dnf install attr

#Raspbian
apt-get install attr

#Docker
docker run cmd.cat/setfattr setfattr

setfattr 命令补充说明:


setfattr 命令,设置文件系统对象的扩展属性,setfattr 命令相关联的新值与扩展属性名称,为每个指定的文件。

setfattr 命令语法:


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

setfattr 命令选项:


-n name, --name=name
  Specifies the name of the extended attribute to set.

-v value, --value=value
  Specifies the new value for the extended attribute.

-x name, --remove=name
  Remove the named extended attribute entirely.

-h, --no-dereference
  Do not follow symlinks. If pathname is a symbolic link, it is not followed, but is instead itself the inode being modified.

--restore=file
  Restores extended attributes from file. The file must be in the format generated by the getfattr command with the --dump option. If a dash ( -) is given as the file name, setfattr reads from standard input.

--version
  Print the version of setfattr and exit.

--help
  Print help explaining the command line options.

--  End of command line options. All remaining parameters are interpreted as file names, even if they start with a dash character.

setfattr 命令参数:


希望设置扩展 attr 属性的目标文件

setfattr 命令实例:


使用 setfattr 可以定义和设置自定义属性:

[root@localhost ~]$ 
setfattr -n user.example -v example anaconda-ks.cfg

[root@localhost ~]$ 
getfattr -d anaconda-ks.cfg

# file: anaconda-ks.cfg
user.example="example"

setfattr 命令查看文件 md5 是否发生变化:

[root@localhost ~]$ 
md5sum anaconda-ks.cfg

fda1aa550d3cf82423d1b1ad1ae53a13  anaconda-ks.cfg



[root@localhost ~]$ 

setfattr -n user.md5sum -v fda1aa550d3cf82423d1b1ad1ae53a13 anaconda-ks.cfg



[root@localhost ~]$ 
getfattr -d anaconda-ks.cfg

# file: anaconda-ks.cfg

user.example="example"
user.md5sum="fda1aa550d3cf82423d1b1ad1ae53a13"

setfattr 命令扩展阅读:




setfattr 命令评论

共收录到 511Linux 命令