lsfd
List open files
TLDR
List all open file descriptors
List all files kept open by a specific program
Check what program has a specific file open
List open IPv4 or IPv6 sockets
Display help
SYNOPSIS
lsof [options]
PARAMETERS
-i [address]
Lists all network files. Can specify an address (e.g., :80 for port 80, TCP for TCP connections, UDP for UDP, @host for connections to a specific host, @host:port).
-u user
Selects files opened by the specified user (username or UID). Can be a comma-separated list or preceded by '^' to exclude.
-p PID
Selects files opened by the specified process ID (PID). Can be a comma-separated list or preceded by '^' to exclude.
+D directory
Lists all files and directories opened within the specified directory and its subdirectories recursively.
+L
Enables the display of file link counts. Helpful for identifying unlinked but still open files (deleted files).
-a
Logically ANDs the selection options. By default, most options are ORed.
-c name
Lists files opened by commands starting with the specified name.
-d FD
Lists files opened with specific file descriptors (FD). Examples include cwd (current working directory), txt (program text), mem (memory-mapped file), or numeric descriptors like 0, 1, 2 (standard I/O), often followed by r (read), w (write), or u (read/write).
-n
Prevents the conversion of network numbers to hostnames for faster output, especially useful when DNS lookups are slow.
-P
Prevents the conversion of port numbers to service names (e.g., 80 instead of http).
-R
Displays the Parent Process ID (PPID) in the output.
-t
Provides a terse output, listing only PIDs, suitable for scripting.
DESCRIPTION
The command lsfd is not a standard Linux command. It is highly probable that the intended command was lsof, which stands for "List Open Files."
lsof is a powerful and versatile command-line utility used to obtain a comprehensive list of all open files and the processes that have opened them. This includes regular files, directories, shared libraries, network sockets, named pipes, and block or character devices. It's an essential tool for system administrators to diagnose various system issues, such as identifying processes holding a specific file, finding out which process is using a particular network port, troubleshooting "file in use" errors, or monitoring system resource usage.
It can filter results based on process ID (PID), user, command name, file type, device, network protocol, and more, making it invaluable for in-depth system analysis and troubleshooting.
CAVEATS
Using lsof effectively often requires root privileges to list all open files on the system; otherwise, it will only show files opened by the invoking user.
The output can be extremely verbose on busy systems, making it necessary to pipe it through tools like grep, awk, or less for filtering and easier analysis.
It can be resource-intensive on systems with a very large number of open files.
UNDERSTANDING <B>LSOF</B> OUTPUT COLUMNS
The default output of lsof presents several columns, each providing crucial information about the open file:
COMMAND: The command name of the process that opened the file.
PID: The Process ID of the process.
USER: The user who owns the process.
FD: The File Descriptor, indicating how the file is being used (e.g., cwd for current working directory, txt for program text, mem for memory-mapped file, or a number followed by r for read, w for write, u for read/write).
TYPE: The type of the file (e.g., REG for regular file, DIR for directory, CHR for character special, BLK for block special, FIFO for named pipe, SOCK for socket).
DEVICE: The device numbers where the file resides.
SIZE/OFF: The size of the file or the offset within the file.
NODE: The inode number of the file.
NAME: The full path to the file, or network information (e.g., IP:port->IP:port for sockets).
COMMON USE CASES FOR <B>LSOF</B>
Here are some common ways to use lsof:
Finding processes using a specific file:
lsof /path/to/your/file
Finding processes using a specific network port:
lsof -i :80 (for TCP port 80) or lsof -i UDP:161 (for UDP port 161)
Listing all open network connections for a user:
lsof -i -u username
Identifying deleted files still held open (potential disk space hog):
lsof | grep deleted
Listing open files for a specific command:
lsof -c sshd
Checking current working directories of processes:
lsof -a -d cwd
HISTORY
lsof was originally developed by Victor A. Abell as a powerful cross-platform utility. Its development began in the early 1990s and it has since become a standard and indispensable tool across various Unix-like operating systems, including Linux, Solaris, HP-UX, AIX, and macOS. Its long history and continuous development reflect its critical role in system administration and troubleshooting.