我在Ubuntu bash中遇到了一个有趣的行为,我无法完全理解。如果我将扩展文件属性添加到文件然后进行更改-属性将从文件中删除。从我的角度来看哪个还可以。
user@user:~/tmp$ echo "aaa" > testattr
user@user:~/tmp$ setfattr --name "user.test" --value "Tested" testattr
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
user@user:~/tmp$ vi testattr
< change something in file and save it >
user@user:~/tmp$ getfattr --name "user.test" testattr
testattr: user.test: No such attribute
但是,如果我使用bash在文件中写入内容-文件属性将保留在原处。有人可以解释这种行为吗?
user@user:~/tmp$ echo "aaa" > testattr
user@user:~/tmp$ setfattr --name "user.test" --value "Tested" testattr
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
user@user:~/tmp$ echo "bbb" > testattr
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
vi正在删除编辑的文件,并用新文件替换。这就是为什么不保留属性的原因。
这是文件操作的日志。
$ mkdir test
$ touch test/file
$ inotifywait -m -r test
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
# vi is now running in another shell
test/ OPEN file
test/ CREATE .file.swp
test/ OPEN .file.swp
test/ CREATE .file.swpx
test/ OPEN .file.swpx
test/ CLOSE_WRITE,CLOSE .file.swpx
test/ DELETE .file.swpx
test/ CLOSE_WRITE,CLOSE .file.swp
test/ DELETE .file.swp
test/ CREATE .file.swp
test/ OPEN .file.swp
test/ MODIFY .file.swp
test/ ATTRIB .file.swp
test/ CLOSE_NOWRITE,CLOSE file
test/ OPEN file
test/ CLOSE_NOWRITE,CLOSE file
test/ MODIFY .file.swp
test/ CREATE 4913
test/ OPEN 4913
test/ ATTRIB 4913
test/ CLOSE_WRITE,CLOSE 4913
test/ DELETE 4913
test/ MOVED_FROM file # old file moved
test/ MOVED_TO file~
test/ CREATE file # new file created
test/ OPEN file
test/ MODIFY file
test/ CLOSE_WRITE,CLOSE file
test/ ATTRIB file
test/ ATTRIB file
test/ MODIFY .file.swp
test/ DELETE file~
test/ CLOSE_WRITE,CLOSE .file.swp
test/ DELETE .file.swp
请参阅此答案以禁用该行为。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句