35

Is there a way to make lsof work continuously to monitor every file that is being opened in real time?

I don't know the name of the process. I want lsof to work continuously for a period of time until I see the the list contains what I want.

Duck
  • 4,434
  • 19
  • 51
  • 64

1 Answers1

48

I believe since you do not know the file name/process id, you could specify user name option as below.

lsof -r 2 -u username
  • The "-r 2" option puts lsof in repeat mode, with updates every 2 seconds. (Ctrl -c quits)
  • The "-u' option can be used to keep an eye on a users activity.

If you know the directory name under which the application is being run and do not want to specify the user name,you could use the command like,

lsof +D /some/dir -r 2 

References

View Network Activity of any application or user in real time

Ramesh
  • 38,687
  • 43
  • 140
  • 215
  • 1
    @DigitalRobot, you could also refer to [this](http://www.thegeekstuff.com/2012/08/lsof-command-examples/) link for more wonderful examples. – Ramesh Sep 23 '14 at 15:11
  • fantastic!!!!!!!!!!!!!! – Duck Sep 23 '14 at 15:18
  • 2
    there is a way to see what has changed in that period ? I mean sometimes the list is very large and I might just want to make something and see which files has been opened in that time. – yucer Dec 07 '15 at 10:38
  • 3
    Could a process open and close a file within the 2 second interval? – CMCDragonkai Dec 15 '15 at 03:46