title: check if file is open with lsof
body: <p>I'm using linux mint 13 xfce and I have a file named <code>wv.gold</code> that I'm trying to check in bash if it's open by any program (for instance, I opened it in <code>sublime-text</code> and <code>gedit</code>)</p>
  
  <p>In many forums people say that if I run <code>lsof | grep filename</code> I should get <code>0</code> if it's open or <code>256(1)</code> if it's closed, but in fact I get nothing (empty string) if I run using <code>grep "wv.gold"</code>, and get a little list if I do it using <code>grep gold</code>.</p>
  
  <p>The list is something like:</p>
  
  <pre><code>bash       2045  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  bash       2082  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  watch      4463  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  gedit     16679  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  lsof      20823  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  grep      20824  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  lsof      20825  user   cwd   DIR   8,1     4096     658031 /home/user/path/to/dir
  </code></pre>
  
  <p>Thus, I get the path to the directory it is but NOT the path to the file (there are other files there) and either way only to <code>gedit</code> process, not to <code>sublime-text</code> process.</p>
  
  <p>Is there some easy way to see if a txt file is opened by any other program?</p>
  
  <p><strong>EDIT</strong>: It turns out (cf. comments from @mata and @ctn) that some editors load files and close them immediately, and they just reopen the file when saving it. This way, we can only see it when they are still opening a big file (since you have the time to observe it while opening) and it disappears immediately after that.</p>