[英]How to add metadata to a folder on mac/linux
If I create a directory like so: 如果我这样创建目录:
mkdir foo
or with node.js 或与node.js
fs.mkdirSync('foo');
is there a way I can add metadata to the folder to indicate that I created it (which user created it, or some other metadata). 有没有一种方法可以将元数据添加到文件夹中以指示我创建了它(哪个用户创建了它,或其他一些元数据)。 How would I read that metadata with bash or node.js? 如何使用bash或node.js读取元数据?
On linux you can add custom metadata to a file as extended attributes , provided that you put them in the user.*
namespace if you're not having the CAP_SYS_ADMIN
capability (~ if you're not root): 在linux上,您可以将自定义元数据作为扩展属性添加到文件中,前提是您将它们放在user.*
名称空间中(如果您没有CAP_SYS_ADMIN
功能(〜如果您不是root用户):
$ setfattr -n user.foobar -v quux file
$ getfattr -n user.foobar file
# file: file
user.foobar="quux"
I'm not using node.js
, but you should look for listxattr()
, setxattr()
, getxattr()
, removexattr()
named shims -- those (and their l*
and f*
variants) are the system call interfaces to extended attributes. 我没有使用node.js
,但您应该查找名为shims的listxattr()
, setxattr()
, getxattr()
, removexattr()
-这些(以及它们的l*
和f*
变体)是系统调用接口扩展属性。
No. The only user-related metadata is the owner of the directory (which will be your user when you create it, but can be changed via the chown
command). 否。唯一与用户相关的元数据是目录的所有者(创建目录时将是您的用户,但可以通过chown
命令进行更改)。
mkdir abc
ls -la
> drwxr-xr-x 2 jerric ORG\Domain Users 64 May 2 11:51 abc
jerric
is the name of the user who created the directory. jerric
是创建目录的用户的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.