2
我在Ubuntu bash中遇到了一个有趣的行为,我无法完全理解。 如果我将扩展文件属性添加到文件,然后更改它 - 从文件中删除属性。从我的角度来看,没问题。扩展文件属性和bash
[email protected]:~/tmp$ echo "aaa" > testattr
[email protected]:~/tmp$ setfattr --name "user.test" --value "Tested" testattr
[email protected]:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
[email protected]:~/tmp$ vi testattr
< change something in file and save it >
[email protected]:~/tmp$ getfattr --name "user.test" testattr
testattr: user.test: No such attribute
但是,如果我用bash写文件 - 文件属性留在原来的位置。 有人可以解释这种行为吗?
[email protected]:~/tmp$ echo "aaa" > testattr
[email protected]:~/tmp$ setfattr --name "user.test" --value "Tested" testattr
[email protected]:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
[email protected]:~/tmp$ echo "bbb" > testattr
[email protected]:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
谢谢你的解释。实际上,我宁愿尝试弄清楚如果文件被改变如何让属性被丢弃=) – incogn1to
@PāvelsReško您可以使用相同的'inotify'库来检测修改后的文件并删除它们的属性。 –
@PāvelsReško实际上'bash'显示了最期望的行为,它会在不删除和重新创建的情况下更改文件内容。在这种情况下,预计不会出现“vi”行为。 –