Command of the day - lsof

  • February 21, 2007
  • Avatar for peter
    Peter
    Upfold

If you need to list all files that are currently open on your Linux or other Unix system, look no further than the lsof command.

On my system (Fedora Core 6), it's located in /usr/sbin/, meaning that you'll need to either run it as root, or specify the full path to the application:

$ /usr/sbin/lsof

It will show you a big long list of all the files that are currently open. On my system, the result from running the command was quite huge, so you might want to pipe the output through less, so you can page up and down through the output at your own pace (q to quit).

$ /usr/sbin/lsof | less

It's useful when you're trying to unmount a device like a USB drive or a CD and the OS won't let you. With lsof you can see exactly what's open, so you can close any offending files and try again (if you're reasonably proficient at the command line, you can grep through the clutter to find what you're looking for). It also comes in handy for other stuff too.

As always, you can read the man page for more advanced options on using the command.

Avatar for peter Peter Upfold

Home » Articles »