2

Linux /MAC 下 vi 或 vim 的编辑再保存改变了文件的什么信息

 2 years ago
source link: https://www.v2ex.com/t/871208
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Java

Linux /MAC 下 vi 或 vim 的编辑再保存改变了文件的什么信息

  choice4 · 2 小时 54 分钟前 · 358 次点击
  1. Java 存在一个线程周期性地向目标文件写入内容 OutputStreamWriter(FileOutputStream) , append 模式.
  2. 在过程中(不要求一定在写入中,可以为两个周期的间隔)使用 vi/vim 工具清空文件内容,如ggdG,保存退出.
  3. 此时如果在该终端使用 tail -f 持续输出该文件内容,无法得到任何结果.
  4. 文件清空后,Java 层面断点跟踪可以正常到达 FileOutputStream#writeBytes(byte[], int, int, boolean) 这个 native 方法,参数均正常,也不会抛出异常.
  5. 如果在保存退出该文件前,已经有一个终端被 tail -f 占用,那么这个终端是可以持续收到写入内容的.
  6. 以上现象我目前环境在 Linux/MacOS/Docker In Linux 稳定复现,Windows 暂未发现此问题(也可能是误测).
  7. 若使用 nano 编辑保存,或 > 重定向为空则不会影响目标文件的输出. 基于以上几点我认为可能 vi 或 vim 在保存退出后会影响文件的一些信息,而这些信息在 Linux/Macos 上用于严格区分文件的唯一性。请问有没有人了解这方便的信息? vi 或 vim 保存退出动作额外改变了文件的什么内容呢?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK