Fact-checked by Grok 2 weeks ago

lsof

lsof (LiSt Open Files) is a command-line utility for operating systems that displays information about s and other resources opened by running processes, including regular s, directories, sockets, device s, and streams. It operates by reading kernel memory to identify open file descriptors, file types, sizes, offsets, and associated process details such as command names, process IDs, and ownership. By default, lsof lists all open s system-wide when invoked without arguments, but it supports extensive filtering options to target specific processes, s, file paths, or connections, making it invaluable for system administration and tasks like identifying resource leaks or blocking processes. Originally developed by Victor A. Abell, a professor at , lsof was first released in 1994 and has since become a standard tool across various Unix dialects. Abell maintained the project for decades, focusing on portability and accuracy in reporting kernel-level file information, with the source code evolving to support dialects including , , macOS (Darwin), NetBSD, , and /. Following Abell's retirement, maintenance transitioned to the open-source lsof-org team via in 2022, where the project continues with bug fixes, enhancements, and community contributions while preserving the original codebase in a "legacy" branch. Key features of lsof include its ability to handle diverse file types beyond traditional files, such as Internet sockets for network diagnostics (e.g., via the -i option to list TCP/UDP connections) and executable libraries or memory-mapped files. It provides formatted tabular output by default but offers parsable formats (e.g., -F for scripting) and repeat modes (e.g., +r for periodic updates), enabling integration with tools like awk or monitoring scripts. lsof is typically installed via package managers on supported systems—such as apt install lsof on Debian-based distributions or yum install lsof on Red Hat—and requires root privileges for comprehensive system-wide scans due to access restrictions on kernel data. In practice, lsof aids in scenarios like locating processes holding a open (e.g., lsof /path/to/file), detecting unlinked but still-accessible files consuming , or network issues by revealing listening ports and remote connections. Its cross-platform support and lightweight design have made it a staple in sysadmin toolkits, with ongoing development ensuring compatibility with modern kernels and security models.

Overview

Purpose and Functionality

lsof, an acronym for "LiSt Open Files," is a command-line utility designed to display information about files opened by processes on operating systems. Developed by Victor A. Abell in the early , it provides detailed output on various file types, including regular files, directories, block and character special files (devices), sockets, libraries, and . In Unix-like systems, the design principle that "everything is a file" treats diverse system resources uniformly through file descriptors, encompassing not only traditional files but also devices, channels, and network connections represented as sockets. This abstraction simplifies system interactions but makes monitoring open files essential for understanding resource usage across processes. At its core, lsof identifies which processes are accessing specific or resources, enabling system administrators to troubleshoot issues, perform audits by detecting unauthorized , and manage resources such as locating in use before unmounting filesystems.

Basic Syntax

The basic syntax of the lsof command follows the form lsof [options] [names], where options are flags that modify the command's behavior and names are positional arguments used to specify targets such as paths. This structure allows users to invoke lsof flexibly, with options controlling aspects like output format or filtering criteria, while positional names primarily target specific or devices by their paths (e.g., lsof /var/log/[syslog](/page/Syslog) to list processes using that ). When invoked without any arguments, lsof lists all open files belonging to all active es owned by the current user. To target other selectors beyond file names, such as IDs (), user IDs (), or command names, dedicated options are used as positional-like selectors: for example, -p PID specifies one or more (e.g., lsof -p 1234), -u UID targets user IDs or login names (e.g., lsof -u [root](/page/Root)), and -c command filters by command names (e.g., lsof -c sshd). These selectors enable precise invocation by combining them with the general syntax, such as lsof -p 1234 /etc/passwd to check a specific file's usage within a given . Full system visibility requires elevated privileges, as non-root users are restricted to their own processes due to security configurations in most distributions; running lsof with sudo (e.g., sudo lsof) grants root access to display open files across all processes. Options like -i for internet files can be incorporated into this syntax for targeted listings, though their detailed effects are covered elsewhere.

History and Development

Origins

lsof was developed by Victor A. Abell at Computing Center in the early 1990s. Abell, serving as associate director, created the tool as a utility for listing information about files opened by processes on Unix systems. In multi-user environments, diagnosing resource usage could be challenging due to limitations of contemporary tools like and , which lacked comprehensive details on file descriptors including regular files, directories, sockets, and devices. lsof addressed these gaps, aiding system administration and . The first public release of lsof, version 2.0, took place in 1994 and was made available as under a permissive granted by the Purdue Research Foundation. This allowed broad distribution and modification without the restrictions typical of agreements, facilitating its integration into various Unix distributions. Early versions focused on core Unix dialects such as BSD and System V Release 4, with initial testing conducted on platforms like AIX and to ensure compatibility across diverse environments. lsof saw adoption in various settings, including at , where it was used to investigate process-file interactions. Its utility was enhanced by contributions from users who provided testing and porting support for additional platforms.

Key Releases

lsof's development has seen several milestone releases that introduced significant enhancements to its functionality and compatibility. Version 4.0 marked a major update in the late 1990s, with the version 4 series beginning around 1999, including early support for networking in dialects like AIX 4.3.x, , and , allowing lsof to display IPv6 socket information alongside traditional IPv4 details. Version 4.89, released on July 7, 2015, focused on improved portability across Unix dialects, with updates to build processes and support for newer compilers, making it easier to compile on modern systems like AIX 7.x. Subsequent releases in the 4.9x series addressed evolving system requirements. Version 4.99, first appearing in late 2023, brought compatibility with Linux kernel 6.x through fixes for kernel interface changes, ensuring reliable file listing on recent distributions. Following Victor A. Abell's retirement, maintenance of lsof transitioned in 2023 to the open-source lsof-org team on GitHub. Key enhancements in this era included better handling of containerized environments, such as Docker, by recognizing namespace-isolated files and processes for more accurate output in virtualized setups. Support for additional file types expanded in the 2000s and beyond, with lsof leveraging kernel APIs to report on devices like USB-mounted filesystems when accessed via standard paths such as /dev or mounted directories. Bug fixes targeted platform-specific issues, including segmentation faults on FreeBSD and backend improvements for macOS using libproc for process file enumeration. Maintenance of lsof remains active under the lsof-org project on , building on the foundational work by Victor A. Abell at , where distributions were historically hosted via FTP. There is no formal semantic versioning scheme; instead, revisions follow a sequential numbering pattern, with incremental updates released as needed for bug fixes and compatibility. Deprecated features include the removal of support for obsolete Unix variants like DEC , Tru64 UNIX, and / starting in version 4.97, streamlining the codebase for contemporary platforms. As of November 2025, the latest stable release is version 4.99.5, incorporating ongoing refinements for performance and dialect support.

Installation and Availability

Supported Platforms

lsof provides primary support for all major operating systems, including various distributions such as and , BSD variants like and , , AIX, , and Darwin-based systems. This compatibility stems from its design to interface with structures across these dialects, ensuring it can list open files and related resources effectively on production environments. As of 2024, maintenance includes fixes and autotools support for AIX 7.2 and 7.3. In the , lsof is natively available on macOS, which is built on the . It can be updated via package managers like Homebrew. Adaptations for Darwin allow it to handle macOS-specific file descriptors, such as those for kernel extensions and system services. Limited or partial support exists for non-native environments, including Windows through emulation layers like , which provides a POSIX-compliant interface, or (WSL), where lsof runs within the subsystem. On , lsof is not included by default but can be installed in Linux-compatible environments such as or compiled from source, requiring root access for comprehensive functionality. lsof's portability relies heavily on POSIX standards for core operations, supplemented by compile-time flags and dialect-specific code to accommodate variations in kernel APIs and file system implementations across supported platforms. This approach enables building tailored versions for optimal performance and feature access on each system, while avoiding dependencies on proprietary elements.

Installation Methods

lsof is commonly installed using system package managers on supported Unix-like operating systems, providing a straightforward method to obtain the tool without manual compilation. On Debian and Ubuntu distributions, administrators can install it via the Advanced Package Tool (APT) by executing the command sudo apt update && sudo apt install lsof. This package is maintained in the official Debian repositories and includes the latest stable version compatible with the distribution. Similarly, on Red Hat Enterprise Linux, CentOS, and Fedora systems, lsof is available through the Yellowdog Updater, Modified (YUM) or DNF package managers; the installation command is sudo dnf install lsof (or sudo yum install lsof on older systems where YUM is the default). For macOS users, Homebrew serves as the primary package manager, allowing installation with brew install lsof, which fetches the tool from the official Homebrew formulae repository. For systems requiring the most recent version or custom configurations, lsof can be compiled from source code. The official distribution is hosted on GitHub under the lsof-org organization, where the latest release can be downloaded as a tarball from the releases page. After extraction, the build process for modern systems (Linux, Darwin/macOS, FreeBSD, NetBSD) uses Autotools: run ./configure to prepare the build for the target dialect, followed by make to compile, and make install to install the binary (typically requiring root privileges). Older versions or legacy dialects may use the ./Configure <dialect> script instead, such as ./Configure linux for Linux systems, before proceeding with make and make install. This method ensures compatibility with specific kernel versions but requires development tools like GCC or Clang, Make, and optionally libtirpc for enhanced RPC support. lsof is often pre-installed by default on many distributions and macOS, eliminating the need for manual setup in standard environments. For instance, it is included in the base system of major distros like , , and , as well as in macOS's command-line tools. To verify availability, users can check with which lsof to locate the or run lsof -v to the version information if installed. Updates to lsof are typically handled through the respective package managers to apply security patches and minor enhancements; for example, on Debian-based systems, sudo apt update && sudo apt upgrade lsof retrieves the latest packaged version. For source-built installations, manual recompilation from the updated release is recommended to incorporate new features or fixes not yet in distribution repositories.

Usage and Options

Command-Line Options

The lsof command supports a variety of command-line options to customize the selection, display, and behavior of the open files listing. These options allow users to target specific processes, users, commands, or resources while modifying the output format for efficiency or parsing. Core selection options focus on process and criteria, while modifiers adjust display details and resource targeting enables network-specific queries. Core options enable precise filtering by process attributes. The -p option specifies one or more IDs (PIDs) to include or exclude in the listing; for example, -p 123 selects files open by 123, while -p ^123 excludes it, and multiple PIDs can be comma-separated like -p 123,456. The -u option targets files by login names or IDs (UIDs), such as -u abe for a specific or -u ^root to exclude the root , with comma-separated sets supporting both names and numeric UIDs. Similarly, -c selects processes by command name prefix, like -c sshd for all processes starting with "sshd", and supports negation with ^ or matching when prefixed with /, as in -c /^sshd/. The -d option limits output to specific file descriptors, such as -d 0 for standard input or -d cwd,1-3 for current and descriptors 1 through 3, with ranges and negations available via ^. Display modifiers optimize output for readability or programmatic use. The -l flag inhibits the conversion of user IDs to login names, displaying numeric UIDs instead to avoid potential lookup delays or errors. The -n option suppresses domain name service (DNS) lookups for network addresses, presenting numeric addresses and numbers directly to improve performance on systems where name resolution might be slow. For machine-readable output, -F specifies a list of fields to include, prefixed by identifiers like p for or f for file type, producing a format suitable for parsing by scripts, with each field terminated by a or NUL character if specified. Resource-specific options target particular file types. The -i flag selects socket files, optionally filtered by , , or , such as -i [TCP](/page/TCP):80 for connections on or -i @1.2.3.4 for a specific , supporting IPv4, , and combinations like -i [UDP](/page/UDP):[email protected]. The -a option enforces logical AND between multiple selection criteria, ensuring only files matching all specified conditions are listed, rather than the default OR behavior. Help and verbose options provide utility information. The -h flag outputs a brief usage summary, listing available options without executing the full command. The -V option displays the lsof version and reports details on items that could not be located, such as inaccessible PIDs or files, aiding in debugging.

Filtering Capabilities

lsof provides flexible filtering mechanisms by allowing users to combine selection options, which by default operate under an OR logic to display the union of matching open files. For instance, specifying both -p 1234 to select files associated with process ID 1234 and -c sshd to select files from processes executing commands starting with "sshd" will list files that match either criterion. This default behavior enables broad queries, but for more precise targeting, the -a option switches to AND logic, requiring files to satisfy all specified selectors; thus, lsof -p 1234 -c sshd -a restricts output to files open by the specific process 1234 only if it is running an sshd command. Similarly, combining -u root (files owned by user root) with -i TCP (Internet socket files using TCP) under -a yields only TCP socket files belonging to root processes. Advanced selectors further refine queries by targeting specific attributes. The +D /path option enables recursive searching of a directory tree for open files, useful for identifying all instances of files within a subtree like /tmp; for example, lsof +D /tmp lists every open file descending from that directory. To filter by network-related file types, the -i option selects Internet socket files, optionally filtered by protocol, address, or port, such as -i TCP:80 for connections on port 80. The -U option selects files exclusively. The -b option prevents lsof from blocking on inaccessible devices or filesystems, such as stalled NFS mounts, allowing queries to proceed without interruption; an example is lsof -b /nfs/mount/point to list open files on a potentially unresponsive filesystem. For device-specific filtering, -N includes NFS files that might otherwise be omitted, ensuring comprehensive coverage in networked environments. Performance optimizations are integral to effective filtering, particularly for large systems. The -n option skips and service name resolution for files, significantly reducing execution time by avoiding DNS lookups; this is especially beneficial in commands like lsof -i -n for quick connection scans. Additionally, +c 0 displays full command names in the output without truncation (default is 9 characters), aiding identification during complex filters such as lsof -c ssh -a +c 0 to reveal complete process names matching the pattern. Error handling in filtering supports streamlined output for scripting or integration. The -t option produces terse listings of only process identifiers (PIDs), suppressing headers and full details, which is ideal for piping to other tools; for example, lsof -t /specific/[file](/page/File) returns PIDs of processes holding that file open, enabling actions like kill -HUP $(lsof -t /u/abe/bar). When combined with selectors, -t maintains the filtering logic while minimizing verbosity, such as lsof -t -p 1234 -a -i [TCP](/page/TCP) to get PIDs for a process's TCP sockets only.

Output Interpretation

Field Descriptions

The standard output of the lsof command is presented in a tabular format with fixed-width columns that provide key details about open files and associated processes. These columns are aligned and separated by spaces, allowing for easy parsing and readability. The following table describes the primary fields in this output:
FieldDescription
COMMANDThe name of the process, truncated to the first nine characters of the executable command associated with the process.
PIDThe process identifier (PID) number assigned to the process.
USERThe user identifier (UID) or login name of the process owner.
FDThe file descriptor, which may be a number (e.g., 0 for standard input), or special values such as cwd (current working directory), txt (executable text), mem (memory-mapped file), or rtd (root directory). This field also includes access mode indicators like r (read), w (write), u (read and write), or a space (unknown mode), followed by lock status if applicable (e.g., N for NFS lock, R for read lock on the entire file).
TYPEThe type of the file, such as REG (regular file), DIR (directory), CHR (character special file), BLK (block special file), FIFO (named pipe), PIPE (unnamed pipe), LINK (symbolic link), IPv4 or IPv6 (Internet socket), or unix (Unix domain socket).
DEVICEThe device on which the file resides, represented by major and minor device numbers in hexadecimal format (e.g., 08:02). For special files, it may show identifiers like -> for links or socket details.
SIZE/OFFThe size of the file in bytes for regular files, or the file offset (current position) if the -o option is used; the column header changes to OFFSET with -o or SIZE with -s. For non-regular files like sockets or pipes, this field displays available content amounts from kernel buffers if determinable, though accuracy varies by system dialect.
NODEThe inode number of the file (in decimal) or, for sockets, the protocol type (e.g., TCP, UDP) or a special identifier like * for unknown. This can be expanded with the +f n option to include node details.
NAMEThe full name of the file, including path for disk files, or detailed connection information for network sockets (e.g., local and remote addresses with ports, such as *:http->example.com:12345); for pipes or FIFOs, it may indicate linked processes or endpoints.
Specialized handling appears in certain fields depending on the file type. For Internet sockets, the NODE field indicates the protocol (e.g., TCP), while the NAME field provides endpoint details including local address and port, remote host and port (if connected), and connection state (e.g., ESTABLISHED); the -T option can enhance the display with additional TCP/TPI information, such as queue sizes and window sizes, in the NAME field. For pipes (TYPE PIPE), the NAME field shows the other endpoint's process details (e.g., pcmd for the command at the other end), and offsets may reflect read/write positions if available. The output format is customizable to refine field content. The -o option forces display of the file offset in all cases, using a 0t (decimal) or 0x (hexadecimal) prefix, while -o0 specifies unlimited decimal digits before switching to hexadecimal, ensuring consistent offset representation even for non-regular files where offsets might otherwise be omitted or approximate. Access modes in the FD field, such as r/w, directly indicate the permissions under which the file is opened, aiding in security analysis. Column headers (e.g., COMMAND, PID) are included by default in the standard tabular output to facilitate interpretation. The -w option suppresses warning messages that could interfere with the output, preserving the clean display of these fields.

Sample Outputs

The default output of the lsof command displays a of open files across all es, with columns including the command name, ID, user, , type, device, size/offset, node, and name. This format provides a comprehensive view but can be lengthy on active systems. For illustration, consider a simplified example focusing on the init , which represents a basic system opening essential files like directories and executables.
COMMAND  PID  USER  FD   TYPE DEVICE SIZE/OFF   NODE NAME
init       1  root cwd    DIR  253,0     4096      2 /
init       1  root rtd    DIR  253,0     4096      2 /
init       1  root txt    REG  253,0  145180 147164 /sbin/init
init       1  root mem    REG  253,0 1889704 190149 /lib/libc-2.12.so
init       1  root  0u    CHR    1,3        0t0  3764 /dev/null
In this output, "COMMAND" indicates the process name (e.g., init), "PID" the process ID (e.g., 1), "USER" the owner (e.g., root), "FD" the file descriptor (e.g., cwd for current working directory, txt for executable text, 0u for standard input with read/write access), "TYPE" the file type (e.g., DIR for directory, REG for regular file, CHR for character device), "DEVICE" the device number, "SIZE/OFF" the file size or offset (e.g., 0t0 for zero size with no offset), "NODE" the inode number, and "NAME" the file path. These fields align with the definitions outlined in the Field Descriptions section. For network-focused output, the lsof -i option filters to show only socket files, such as connections, revealing listening ports and remote details. A representative example involves an SSH server listening on port 22, demonstrating how lsof captures , address family, and connection state.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd   1471 [root](/page/Root) 3u IPv4 12683 0t0      [TCP](/page/TCP) *:ssh (LISTEN)
sshd   1471 [root](/page/Root) 4u [IPv6](/page/IPv6) 12685 0t0      [TCP](/page/TCP) *:ssh (LISTEN)
Here, the output highlights network-specific details: "TYPE" as IPv4 or IPv6 for address family, "NAME" including the protocol (TCP), local port (ssh or 22), and state (LISTEN for waiting connections). No remote client is shown in listening mode, but established connections would include source and destination IP:port pairs (e.g., 192.168.1.100:ssh->192.168.1.200:12345 (ESTABLISHED)). For a web server scenario, replacing :22 with :80 would similarly list processes like httpd or nginx bound to port 80. When run without sufficient privileges (e.g., as a non-root user), lsof encounters permission errors, resulting in incomplete output with explicit denial messages for inaccessible paths or directories. This occurs because lsof relies on reading /proc entries, which are restricted for other users' processes. A sample output from a non-root execution shows such failures for system processes like init.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init      1 root cwd unknown /proc/1/cwd (readlink: Permission denied)
init      1 root rtd unknown /proc/1/root (readlink: Permission denied)
init      1 root txt unknown /proc/1/exe (readlink: Permission denied)
init      1 root NOFD         /proc/1/fd (opendir: Permission denied)
kthreadd  2 root cwd unknown /proc/2/cwd (readlink: Permission denied)
Annotations include (readlink: Permission denied) for failed path resolutions and (opendir: Permission denied) for inaccessible file descriptor directories, marked as unknown or NOFD (no file descriptors). To mitigate these without elevating privileges, the -b option instructs lsof to avoid certain kernel functions like readlink(2) and stat(64), skipping problematic entries silently instead of reporting errors. For instance, lsof -b on the same system would omit the denial messages and list only accessible files, though at the cost of incomplete paths (e.g., showing device numbers without full names). The -F option produces a parsable, field-oriented output suitable for scripting, where each line begins with a single-character identifier for the field (e.g., p for , c for command, f for , n for name), followed by the value, enabling easy parsing with tools like or . Specifying subsets like -Fpcfn limits to ID, command, , and name. A basic example for a might appear as:
p315
cinit
fcwd
n/
This format groups fields per open file instance, with a newline separating records; for scripting, it allows extraction without column parsing, such as grepping for p lines to get PIDs. The full set of field identifiers (e.g., a for mode, t for type) is documented in the man page for custom selection.

Practical Applications

Process Monitoring

lsof serves as a vital tool for monitoring active es by revealing the files, sockets, and other resources they hold open, enabling administrators to assess and detect anomalies in real-time or targeted inspections. By specifying process identifiers (PIDs), users can isolate and examine individual processes without scanning the entire system, which is particularly useful for identifying inefficiencies or potential issues in resource-intensive applications. To identify resource hogs, such as consuming excessive file descriptors, the -p option allows listing open files for a specific ; for instance, lsof -p 1234 displays all resources used by process ID 1234, including the count and types of open files. In a context, this can reveal open files contributing to high resource usage. For example, in environments, lsof helps track open files per process to diagnose descriptor limits. The output includes columns for command, , , and file descriptors, providing a of potential bottlenecks without requiring additional tools. Detecting orphan files—those deleted but still held open by processes—is achieved by filtering lsof output for the "(deleted)" marker in the NAME column, commonly via lsof | [grep](/page/Grep) deleted, which lists processes retaining space on disk despite file removal. This command identifies culprits like long-running services or errant applications, allowing targeted restarts to reclaim storage; for example, it might show a holding a large deleted log file. For real-time process monitoring, lsof integrates with the watch utility to periodically refresh output, such as watch lsof -i to observe evolving network-related file activity tied to es, updating every few seconds to track dynamic resource engagement. Alternatively, lsof's built-in repeat mode with -r (e.g., lsof -p 1234 -r 10) automates refreshes at set intervals, aiding in proactive observation of behavior over time without scripting. In security contexts, facilitates checks on unknown or suspicious processes by listing their open files with options like -p PID or -u username, helping spot through unusual file accesses, such as unexpected network sockets or hidden executables. For instance, examining files opened by an unidentified can reveal connections to malicious payloads or unauthorized attempts, as recommended in incident response practices. This approach, combined with user or PID filtering, supports auditing without full system scans, emphasizing process-specific anomalies.

System Troubleshooting

lsof serves as a vital diagnostic tool for resolving file lock contention, where processes hold exclusive access to , preventing operations like updates or deletions. Administrators frequently encounter "file in use" errors during software installations or maintenance; executing lsof /path/to/[file](/page/File) reveals the processes and file descriptors involved, such as a holding a lock on /var/lib/[dpkg](/page/Dpkg)/lock. This output includes the ID (), command name, and lock status (e.g., 'w' for write lock), enabling targeted termination of the offending via kill to release the lock without rebooting. For instance, in a scenario where an interrupted update leaves a lock inaccessible, lsof identifies the stale , restoring functionality. Detecting potential memory leaks often involves scrutinizing open file handles, as applications may accumulate excessive descriptors without closing them, leading to resource exhaustion. By running lsof -p PID on a suspected process, users can inspect the SIZE and OFF columns, which display the file size and offset; unusually large values, such as gigabytes in log accumulators like /var/log/app.log, signal unchecked growth from unrotated or leaking files. Similarly, lsof | grep deleted uncovers files marked for deletion but still held open, consuming disk space akin to a leak until the process exits. This approach helps quantify the scale of the issue, where hundreds of open descriptors per process exceed typical limits (e.g., 1024 default ulimit), prompting code reviews or restarts to mitigate performance degradation. Network-related troubleshooting with lsof excels at pinpointing port conflicts and persistent connections that disrupt services. The command lsof -i :port lists processes bound to a specific port, such as port 80 for HTTP, displaying details like the listening PID and connection state (e.g., ESTABLISHED or LISTEN); this resolves errors where a new web server fails to bind due to a lingering process from a prior instance. For hanging connections in database services, filtering with lsof -i TCP:3306 reveals idle sockets, allowing administrators to identify and close them to free resources and restore responsiveness. Such diagnostics prevent cascading failures, as unresolved conflicts can lead to service downtime affecting multiple users. Post-reboot boot-time issues, such as stuck filesystem mounts or inaccessible device files, can be diagnosed by scanning for residual open handles with lsof +D /, which recursively examines the entire tree for open files and directories. This reveals processes clinging to unmounted devices, like an init script holding a reference to /dev/sda1, causing delays in subsequent mounts or . By including options like -x fl to cross mount points, lsof uncovers hidden dependencies, such as NFS shares with stale locks, enabling manual unmounts via umount -l or kills to expedite . In environments with complex sequences, this method provides a comprehensive view without invasive , ensuring quicker resolution of hangs that prolong startup times.

Limitations and Alternatives

Known Limitations

lsof exhibits several inherent limitations stemming from its reliance on operating system privileges, interfaces, and platform-specific implementations. When executed by non-root users, lsof is restricted to displaying only open files belonging to with the same user ID as the invoking , due to measures like the HASSECURITY compilation option, which prevents unauthorized access to other users' information. This privilege gap means that files opened by running under different user IDs, including or setgid binaries, may remain invisible unless lsof is run with elevated privileges, as access to /proc//fd directories for other users requires permissions. Kernel dependencies further constrain lsof's accuracy and completeness. On customized or modified , rapid changes in structures can lead to unpredictable or incomplete output, as lsof parses data directly via /dev/kmem or /proc interfaces, and mismatches between build-time headers and versions may cause failures. In containerized environments like , network namespaces obscure socket information, resulting in incomplete listings such as unidentified 'sock' entries or empty output for lsof -i, since processes in isolated namespaces appear detached from the host's view of PIDs and file descriptors. Additionally, lsof lacks native for -level files or structures without corresponding loadable modules, limiting visibility into dynamically loaded components like AFS volumes where node numbers may be blank without address access. Performance overhead becomes noticeable on systems with high resource utilization, particularly on where lsof scans the /proc filesystem for every active to enumerate open files. This can take several minutes and consume nearly 100% CPU on servers with thousands of or open file descriptors, as each /proc entry requires stat() calls and memory parsing, exacerbating delays during peak loads. Options like +D for descent amplify this issue on large filesystems, demanding significant dynamic and time. Portability challenges arise across UNIX dialects and non- systems, where certain command-line options and features, such as support or the +m option for points, are unavailable or behave differently due to varying name caches and numbering schemes. For instance, path name components for advanced filesystems may not be resolvable on dialects like AIX or , and lsof's effectiveness diminishes on very recent filesystem implementations where integration lags, as seen in incomplete reporting for snapshot-based structures. These variations are detailed in platform-specific documentation, underscoring lsof's optimization for standard environments over diverse or emerging ones. Several command-line utilities complement or serve as alternatives to lsof for investigating file and network usage in systems. The fuser command identifies processes using specific files, sockets, or file systems by listing their process IDs (PIDs) along with access types, such as open files or current directories. Unlike lsof, which provides comprehensive details including command names, user IDs, and file descriptors, fuser offers a simpler output focused on PIDs and is particularly useful for quickly identifying and killing processes to unmount busy file systems, such as with the -k option to send SIGKILL signals. For block device management, lsblk lists storage devices, partitions, and mount points in a tree structure, providing details like file system types and sizes without focusing on open file usage. In contrast, lsof's -i option reveals network sockets (TCP/UDP) tied to specific processes, offering process-level insights that lsblk lacks for block devices. Basic socket statistics can be obtained via netstat or its modern replacement ss, which display active connections, ports, and states. With the -p option (requiring elevated privileges), ss can show process names and PIDs associated with sockets, though it provides less detailed file descriptor and open file information compared to lsof, making it suitable for high-level network diagnostics. In programmatic contexts, the library psutil serves as a cross-platform alternative by enabling scripts to retrieve open files per process, including paths, file descriptors, and modes, similar to lsof's output but integrated into application code for automation. For dynamic tracing of file operations, monitors system calls like open() in for running processes, capturing new file accesses that lsof's snapshot view might miss, though it generates verbose logs requiring filtering for usability. lsof often pairs with complementary tools for broader system analysis, such as or to correlate PIDs with resource usage, or auditd to log file access events persistently across sessions.

References

  1. [1]
    lsof(8) - Linux manual page - man7.org
    Note that many UNIX dialects do not supply all command name characters to lsof in the files and structures from which lsof obtains command name. ... line contains ...
  2. [2]
    How to use the lsof command to troubleshoot Linux - Red Hat
    Dec 9, 2022 · Despite its seemingly humble purpose, the lsof tool is a powerful tool on a system that can treat almost anything as a file. Read the lsof man ...
  3. [3]
    lsof
    ### Summary of lsof
  4. [4]
    lsof-org/lsof: LiSt Open Files - GitHub
    This repository is for maintaining the final source tree of lsof inherited from Vic. "legacy" branch keeps the original source tree.
  5. [5]
    lsof Command in Linux with Examples - phoenixNAP
    Oct 23, 2024 · ... is a practical sysadmin tool that prints a list of all open files in Linux ... The lsof command allows multiple search items on the command line.
  6. [6]
    Vic Abell's Home Page - FreeBSD
    The free, open-source, Unix administrative tool lsof (for LiSt Open Files) displays information about files open to Unix processes. It runs on many Unix ...Missing: command | Show results with:command
  7. [7]
    LSOF: How to List Open Files in Unix Systems - Unixmen
    For security analysis: You can use the lsof command to detect unauthorized access or suspicious file activities. To monitor your system. If you want to ...
  8. [8]
    40 lsof commands every admin needs to know - Cloudfanatic
    The most common usage of lsof is debugging system issues. Linux network admins also rely on lsof when troubleshooting network issues. Our editors have ...
  9. [9]
    [PDF] Frequently Asked Questions about lsof - HPE Community
    This file contains frequently asked questions about lsof and answers to them. Vic Abell <abe@purdue.edu>. July 6, 2004. Table of Contents: 1.0 General ...
  10. [10]
    Anecdotes - The PUCC Archive
    lsof was developed and maintained by Vic Abell during his tenure at PUCC. lsof, originally released in 1994, is used to list the open files on a system, find ...Missing: Victor | Show results with:Victor
  11. [11]
    lsof License | Software Package Data Exchange (SPDX)
    Copyright 2002 Purdue Research Foundation, West Lafayette, Indiana 47907. All rights reserved. Written by Victor A. Abell. This software is not subject to ...Missing: command | Show results with:command
  12. [12]
    http://web.mit.edu/darwin/src/modules/lsof/lsof/00...
    The NetBSD dialect version of lsof is compiled using the dialect sources it shares with OpenBSD in the n+obsd dialect subdirectory. NEXTSTEP and OPENSTEP ...
  13. [13]
    Requesting updated lpp package of lsof | Open Source Development
    The version of lsof available for download from AIX Web Download Pack Programs MRS is version 4.89 which was released July 7, 2015.<|control11|><|separator|>
  14. [14]
    Releases · lsof-org/lsof - GitHub
    Nov 17, 2024 · Introduce alpha version of liblsof which allows users to use lsof functionality via C functions instead of spawning a subprocess and parsing the output.Missing: history | Show results with:history
  15. [15]
  16. [16]
  17. [17]
    finding pid for a port without busybox in Android - Stack Overflow
    Jul 11, 2018 · lsof -i is not available for Android. 1.cat /proc/net/tcp. you will get a list of all ports with their processes.List all files opened by my Android App - Stack Overflowhow to check open file without lsof - Stack OverflowMore results from stackoverflow.com
  18. [18]
    lsof - Homebrew Formulae
    lsof. Install command: brew install lsof. Utility to list open files. https://github.com/lsof-org/lsof. License: lsof. Formula JSON API: /api/formula/lsof.
  19. [19]
    Getting started - lsof - Read the Docs
    You can get lsof by building from source or installing from package managers. Due to the nature that lsof talks to the kernel, it requires many build-time ...
  20. [20]
    How to Use the 'lsof' Command in Linux - Hongkiat
    Sep 12, 2023 · How to Install the lsof Command. In many Linux distributions, the lsof command comes pre-installed. However, if it's not available on your ...
  21. [21]
    10 lsof (List of Open Files) Command Examples in Linux - Tecmint
    Jul 14, 2023 · lsof meaning 'LiSt Open Files' is used to find out which files are open by which Linux process. As we all know Linux/Unix considers everything as a file.
  22. [22]
    lsof command - FreeKB
    Dec 13, 2020 · The lsof command without any options should return something like this. Notice in this example that many of the files have "Permission denied".Missing: sample output
  23. [23]
    lsom and lsof Command Reference - Oracle Help Center
    Usage Notes. Use the ls of file lsof to list the Oracle process identifiers of all processes that have the specified file open.
  24. [24]
    Why is space not being freed from disk after deleting a file in Red ...
    Aug 7, 2024 · First, obtain a list of deleted files which are still held open by applications: Raw. $ lsof | egrep "deleted|COMMAND" COMMAND PID TID ...
  25. [25]
    Investigating Linux Process File Descriptors for Incident Response ...
    Jan 6, 2021 · A file descriptor is a handle to access files/I/O. Use `ls -al /proc/<PID>/fd` to view them, and `lsof -p <PID>` to see all open files.
  26. [26]
    Part 4 of 5: Making Linux Security Accessible Blog Series
    Apr 7, 2025 · Processes running as an unexpected user. To investigate a suspicious process: $ ps -p 1234 -f. $ sudo lsof -p 1234. $ sudo lsof -i - ...
  27. [27]
    None
    Below is a merged summary of the known limitations of `lsof` based on the provided segments. To retain all information in a dense and organized manner, I’ve used tables in CSV format where appropriate, followed by a narrative summary for additional context and details not easily tabularized. The response includes all points from the four segments, with useful URLs consolidated at the end.
  28. [28]
    In lsof output what are those 'sock' lines? - Server Fault
    Jan 25, 2020 · 'sock' lines in lsof mean lsof can't find more info, often due to the process being in another network namespace, like a container. Normally,  ...
  29. [29]
    Why does the command "lsof" run very slowly and consume high cpu
    May 6, 2025 · Issue. Executing lsof takes a very long time (up to several minutes). Executing lsof consumes an entire CPU for a very long time.Missing: performance scanning
  30. [30]
    linux - lsof runs very slow in my server
    Mar 20, 2015 · The weird thing is the execution of 'sudo lsof' takes about two minutes to finish and it uses 99.x% CPU during that two minutes.linux - How to check disk I/O utilization per process? - Server Faultlsof runs REALLY slow when Chromium or Firefox is openMore results from serverfault.comMissing: scanning | Show results with:scanning
  31. [31]
    fuser - identify processes using files or sockets - Ubuntu Manpage
    fuser displays the PIDs of processes using the specified files or file systems. In the default display mode, each file name is followed by a letter denoting the ...
  32. [32]
    fuser(1) - Linux man page
    ### Description of fuser
  33. [33]
    System insights with command line tools: lsof and lsblk
    Sep 11, 2024 · These tools are particularly useful for investigating open files, active network connections, and mounted block devices on your Fedora Linux system.
  34. [34]
    netstat and Its Alternatives | Baeldung on Linux
    Sep 20, 2024 · Unlike netstat, lsof provides more detailed information about the processes associated with network connections.Missing: authoritative sources
  35. [35]
  36. [36]
    Monitor file access by Linux processes
    Linux is powerful with the help of small utilities like lsof and strace. They help with monitoring disk and file activity, of new and running processes.
  37. [37]
    lsof(8): open files - Linux man page
    The optional "m<fmt>" argument specifies a format for the marker line. The <fmt> characters following 'm' are interpreted as a format specification to the ...