Exploring the "lsof" command

By Alvin J. Alexander, devdaily.com

The Unix lsof command lists information about files that are open by processes running on the system.

Typing the lsof command by itself lists all open files belonging to all active processes on the system:

lsof

List all open files belonging to PID (process ID) 11925:

lsof -p 11925

List all open files belonging to processes owned by the user named "al":

lsof -u al

List files open in the directory specified, but don't descend into sub-directories:

lsof +d '/Users/al'

The next command lists files that are open in the directory specified, and also descends into sub-directories. Beware: this can take a very long time to run for large directory structures:

lsof +D '/Users/al'

devdaily logo