扩展文件属性和bash

 GloryWumie 发布于 2023-02-10 11:01

我在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

请参阅此答案以禁用该行为.

1 个回答
  • 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
    

    请参阅此答案以禁用该行为.

    2023-02-10 11:04 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有