Thursday, December 11, 2008

List Open Files (lsof)

The lsof program is a great tool to find open files. One case you might need this is to find a process that has an open file on a device you are trying to unmount. Another is if you want to determine what files a certain process is opening.

List your own open files (includes sockets and pipes):
lsof

List all open files on the system (includes sockets and pipes), must be root:
lsof

List open files for certain processes, must be root:
lsof -c pattern
where pattern is the first few letters of the process name or a regular expression between forward slashes /regexp/.

List all open network sockets, must be root:
lsof -i
Useful to make sure something unexpected isn't listening to the network.