Back to the command reference

lsof

ProcessesAdvanced In real Linux

List open files and network connections

Name: lsof = list open files

This command needs a real Linux system; you can practise it in real Linux mode.

Description

lsof lists files opened by processes. Since everything is a file on Linux, that includes directories, devices, pipes and network sockets.

Use it to find who holds a port (lsof -i :80), why a partition won't unmount (lsof /mnt/usb) or why deleted files still take space.

Syntax

lsof [OPTION]...

Common options

-iNetwork connections, e.g. -i :80 for port 80
-p PIDFiles opened by a process
-u USERFiles opened by a user
-c NAMEOnly processes whose command starts with NAME
+D DIRWho has files open under DIR (when unmounting fails)
-tPrint only process IDs (kill $(lsof -t -i :8080))
-nDo not look up host names (faster)
-PNumeric ports, not service names

Examples

  • $ sudo lsof -i :8080

    Who is using port 8080

    Explain
  • $ lsof /var/log/syslog

    Who has this file open

    Explain

Related