I use tail -f filename
monitoring a text file,and use vi
editor adding a line at the end of the file.
But after saving the file I did not see the update on the terminal which 'tail -f
' are monitoring.
What is the problem? Is vi
editor has buffer or something?
vi/vim copy the file to a temporary file, 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
So the file you're tailing is listed there, and the .temp3.swp vim has created as well.
Once you save the file, vim deletes the original and renames the .temp3.swp file to temp3.swp
lsof will show you're tailing a deleted file:
[root@mg ~]# lsof | grep temp3
tail 29146 root 3r REG 253,0 2474 2228230 /root/temp3~ (deleted)
stat will show you the new file has the inode of the .temp3.swp file above:
[root@mg ~]# stat temp3
File: 'temp3'
Size: 2482 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2228273 Links: 1