简体   繁体   中英

How to add metadata to a folder on mac/linux

If I create a directory like so:

mkdir foo

or with 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?

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):

$ 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.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM