Consider this simple scenario:
- I open a text file ~/textfile.txt with
vim
in one terminal (tried with both edit and read-only modes). - In a different terminal, I run
/usr/sbin/lsof ~/textfile.txt
Get no results
Why?
lsofopen filesvim
Consider this simple scenario:
vim
in one terminal (tried with both edit and read-only modes)./usr/sbin/lsof ~/textfile.txt
Get no results
Why?
Best Answer
When you use
vi
/vim
to edit a file you aren't actually holding~/<filename>
open you are reading the file into~/.<filename>.swp
and then holding that temp file open.If you run
lsof ~/.<filename>.swp
it will show you the information you are looking for.NOTE: If you have multiple people editing the same file you will need to
lsof ~/.<filename>.s*
as eachvi
/vim
session will create its own swap file but will name it differently