我在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"
Grzegorz Żur.. 5
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
请参阅此答案以禁用该行为.
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
请参阅此答案以禁用该行为.