linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Commands/cmd-lsof

kb/commands ── Commands ── intermediate

lsof: who has what open

`lsof` (List Open Files) shows every open file across all processes. In Linux everything is a file, so that includes regular files, sockets, and pipes.

view as markdownaka: list-open-files

Why use it

When you need answers to questions like:

  • "Which process holds this port?"
  • "What has this file locked?"
  • "Why is the disk full when du shows little usage?"

lsof is the tool to reach for. Without sudo it shows only your own processes; with sudo it shows all of them.

Most common forms

bash
lsof -p 1234              # all fds of a specific [[process-and-pid]]
lsof -i                    # all network sockets
lsof -i :8080              # who is listening on or connected to port 8080
lsof -i tcp                # TCP only
lsof -nP -i                # no resolution: -n skips host lookup, -P skips port lookup
lsof /var/log/app.log      # who has this specific file open
lsof +D /var/lib/docker    # all open files inside a directory (-D = recurse)

Most useful one-liner: lsof | grep deleted

When df -h shows the disk full but du -sh / does not:

bash
sudo lsof | grep deleted

These are processes that hold open a file already removed from the filesystem. The inode stays alive until the file descriptor is closed. The most common culprit is an application with log rotation that never reopened its log file.

Output columns

COMMAND  PID  USER  FD   TYPE  DEVICE  SIZE/OFF  NODE  NAME
nginx    900  www   6u   IPv4  12345   0t0      TCP    *:80 (LISTEN)
  • FD: number plus access mode. 6u is fd 6, open for read+write. cwd, rtd, txt, and mem are special types (cwd = current directory, txt = binary, mem = mmap).
  • TYPE: REG (regular file), DIR, CHR (char device), IPv4/IPv6, unix, FIFO.
  • NAME: path, or host:port -> host:port for sockets.

Alternative via /proc

Without lsof you can see the same information through /proc/<pid>/fd/*:

bash
ls -l /proc/900/fd/        # each fd is a symlink to its target

lsof is a convenient aggregator of exactly that data.

§ команды

bash
lsof -p $(pgrep -x nginx)

All open files for a specific process

bash
sudo lsof -i :8080

Who is listening on or connected to port 8080

bash
sudo lsof | grep deleted

Deleted-but-still-open files, candidates for a mysteriously full disk

bash
lsof -nP -i tcp

All TCP connections on the system without name resolution

bash
lsof -t -i :8080 | xargs -r kill

Kill all processes holding port 8080 (-t = PIDs only)

§ см. также

  • cmd-psps: process snapshotps prints a snapshot of processes at the moment it runs. Two dialects: BSD (`aux`, no dash) and UNIX (`-ef`, with dash). `-o` specifies columns. For continuous monitoring, use [[cmd-htop|htop]].
  • cmd-htophtop: interactive process monitorhtop is an interactive TUI process monitor. F-keys: F3 search, F4 filter, F5 tree, F6 sort, F9 kill. Color meters at the top, process list below. It replaces top wherever it is available.
  • cmd-stracestrace: what syscalls a process makes`strace` shows in real time which system calls a process makes and with what arguments. The primary tool when a process goes silent.
  • cmd-lsblk-blkidlsblk and blkid: block devices and UUIDslsblk shows the block device tree (disk -> partition -> LVM/crypt -> mountpoint). blkid prints UUID, LABEL, and filesystem type. Use them together to write a [[mount-and-fstab|/etc/fstab]] entry by UUID.
  • file-descriptorsFile descriptors (stdin, stdout, stderr)A file descriptor is an integer a process uses to reach an open file, socket, or pipe. Every process gets 0/1/2 = stdin/stdout/stderr.
  • cmd-ssss: who is listening and who is connected`ss` is the modern replacement for netstat. It shows sockets in LISTEN and ESTABLISHED state, supports filters by address, port, and state, and provides extended TCP info.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies