lsof to the rescue!
Tuesday, April 15th, 2008
Have you ever got the error message ‘device is busy‘ and you had no idea what or who is using the device? In situations like this lsof is your best friend. Probably one of my favorite Linux commands. Name of the command stands for list open files and because everything in Linux is a file you can use it to gather information about virtually everything. When you execute it without any parameters it will display all the files that are open on your system.
To see all the files opened by process nautilus type
$ lsof -c nautilus.
To see all files opened by user ralphz type
$ lsof -u ralphz.
You can also check open files by process ID:
$ lsof -p 1233.
And one of the coolest features is to list all files that are currently open in the specified directory (recursively):
$ lsof +D /home/thor.
You can even chaeck what process and user are connected to a specific Internet host:
$ lsof -i@www.google.com.
That’s not all! Tones of other functions are available. Check man lsof for more info.
