linux 命令 "tail -f filename" 不起作用

linux command "tail -f filename" doesnt work

我使用tail -f filename监控一个文本文件,并使用vi编辑器在文件末尾添加一行。

但是保存文件后,我没有在“tail -f”正在监视的终端上看到更新。

有什么问题? vi 编辑器有缓冲区什么的吗?

vi/vim复制文件到临时文件,vis:

[root@mg ~]# lsof | grep temp3 tail 29146 root 3r REG 253,0 2474 2228230 /root/temp3 vim 29260 root 4u REG 253,0 12288 2228273 /root/.temp3.swp

所以您拖尾的文件列在那里,并且 .temp3.swp vim 也已创建。

保存文件后,vim 会删除原始文件并将 .temp3.swp 文件重命名为 temp3.swp

lsof 将显示您正在跟踪已删除的文件:

[root@mg ~]# lsof | grep temp3 tail 29146 root 3r REG 253,0 2474 2228230 /root/temp3~ (deleted)

stat 将显示新文件具有上述 .temp3.swp 文件的索引节点:

[root@mg ~]# stat temp3 File: 'temp3' Size: 2482 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 2228273 Links: 1