lsof is a command meaning "list open files", which is used in many
Unix-like
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
systems to report a list of all open files and the processes that opened them. This
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
utility was developed and supported by Victor A. Abell, the retired Associate Director of the
Purdue University
Purdue University is a public land-grant research university in West Lafayette, Indiana, and the flagship campus of the Purdue University system. The university was founded in 1869 after Lafayette businessman John Purdue donated land and ...
Computing Center. It works in and supports several Unix flavors.
A replacement for Linux, , is included in
util-linux
is a standard package distributed by the Linux Kernel Organization for use as part of the Linux operating system. A fork, (with meaning "next generation"), was created when development stalled, but has been renamed back to , and is the off ...
.
RFC: lsfd, a brand new Linux specific replacement for lsof #1418
/ref>
Examples
Open files in the system include disk files, named pipe
In computing, a named pipe (also known as a FIFO for its behavior) is an extension to the traditional pipe concept on Unix and Unix-like systems, and is one of the methods of inter-process communication (IPC). The concept is also found in OS/ ...
s, network sockets and devices opened by all processes. One use for this command is when a disk cannot be unmounted because (unspecified) files are in use. The listing of open files can be consulted (suitably filtered if necessary) to identify the process that is using the files.
# lsof /var
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
syslogd 350 root 5w VREG 222,5 0 440818 /var/adm/messages
syslogd 350 root 6w VREG 222,5 339098 6248 /var/log/syslog
cron 353 root cwd VDIR 222,5 512 254550 /var -- atjobs
To view the port associated with a daemon:
# lsof -i -n -P , grep sendmail
sendmail 31649 root 4u IPv4 521738 TCP *:25 (LISTEN)
From the above one can see that "sendmail" is listening on its standard port of "25".
;: Lists IP sockets.
;: Do not resolve hostnames (no DNS).
;: Do not resolve port names (list port number instead of its name).
One can also list Unix Sockets by using lsof -U
.
Lsof output
The lsof output describes:
*the identification number of the process (PID) that has opened the file;
*the process group identification number (PGID) of the process (optional);
*the process identification number of the parent process (PPID) (optional);
*the command the process is executing;
*the owner of the process;
*for all files in use by the process, including the executing text file and the shared libraries it is using:
**the file descriptor number of the file, if applicable;
**the file's access mode;
**the file's lock status;
**the file's device numbers;
**the file's inode number;
**the file's size or offset;
**the name of the file system containing the file;
**any available components of the file's path name;
**the names of the file's stream components;
**the file's local and remote network addresses;
**the TLI network (typically UDP) state of the file;
**the TCP state, read queue length, and write queue length of the file;
**the file's TCP window read and write lengths (Solaris only); and
**other file or dialect-specific values.
For a complete list of options, see the Lsof(8) Linux manual page
See also
*fuser (Unix)
The Unix command fuser is used to show which processes are using a specified computer file
A computer file is a computer resource for recording data in a computer storage device, primarily identified by its file name. Just as words can be w ...
*stat (Unix)
is a Unix system call that returns file attributes about an inode. The semantics of vary between operating systems. As an example, Unix command uses this system call to retrieve information on files that includes:
* atime: time of last acce ...
*netstat
In computing, netstat (''network statistics'') is a command-line network utility that displays network connections for Transmission Control Protocol (both incoming and outgoing), routing tables, and a number of network interface (network interf ...
*strace
strace is a diagnostic, debugging and instructional userspace utility for Linux. It is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process st ...
*List of Unix commands
This is a list of Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems.
List
See also
* List of G ...
References
External links
Old site
lsof-l mailing list
mirror of legacy sources
*
*
Using lsof
Lsof FAQ
*Sam Nelson'
PCP
script, an alternative to "lsof -i" for Solaris.
Glsof
is two separate utilities (Queries and Filemonitor) based on lsof.
Sloth
is a macOS graphical interface for lsof
{{Unix commands
Unix file system-related software