neulab/tldr huggingface dataset:
Create baz.tar.xz with the preset -4e (-4 --extreme), which is slower than e.g. the default -6, but needs less memory for compression and decompression (48 MiB and 5 MiB, respectively):
tar cf - baz | xz -4e > baz.tar.xz
A mix of compressed and uncompressed files can be decompressed to standard output with a single command:
xz -dcf a.txt b.txt.xz c.txt d.txt.lzma > abcd.txt
Parallel compression of many files On GNU and *BSD, find(1) and xargs(1) can be used to parallelize compression of many files:
find . -type f \! -name '*.xz' -print0 \ | xargs -0r -P4 -n16 xz -T1
The -P option to xargs(1) sets the number of parallel xz processes.  The best value for the -n option depends on how many files there are to be compressed.  If there are only a couple of files, the value should probably be 1; with tens of thousands of files, 100 or even more may be appropriate to reduce the number of xz processes that xargs(1) will eventually create.
The option -T1 for xz is there to force it to single-threaded mode, because xargs(1) is used to control the amount of parallelization.
Robot mode Calculate how many bytes have been saved in total after compressing multiple files:
xz --robot --list *.xz | awk '/^totals/{print $5-$4}'
A script may want to know that it is using new enough xz.  The following sh(1) script checks that the version number of the xz tool is at least 5.0.0.  This method is compatible with old beta versions, which didn't support the --robot option:
if ! eval "$(xz --robot --version 2> /dev/null)" || [ "$XZ_VERSION" -lt 50000002 ]; then echo "Your xz is too old." fi unset XZ_VERSION LIBLZMA_VERSION
Set a memory usage limit for decompression using XZ_OPT, but if a limit has already been set, don't increase it:
NEWLIM=$((123 << 20))  # 123 MiB OLDLIM=$(xz --robot --info-memory | cut -f3) if [ $OLDLIM -eq 0 -o $OLDLIM -gt $NEWLIM ]; then XZ_OPT="$XZ_OPT --memlimit-decompress=$NEWLIM" export XZ_OPT fi
Custom compressor filter chains The simplest use for custom filter chains is customizing a LZMA2 preset. This can be useful, because the presets cover only a subset of the potentially useful combinations of compression settings.
The CompCPU columns of the tables from the descriptions of the options -0 ... -9 and --extreme are useful when customizing LZMA2 presets.  Here are the relevant parts collected from those two tables:
Preset   CompCPU -0         0 -1         1 -2         2 -3         3 -4         4 -5         5 -6         6 -5e        7 -6e        8
If you know that a file requires somewhat big dictionary (e.g. 32 MiB) to compress well, but you want to compress it quicker than xz -8 would do, a preset with a low CompCPU value (e.g. 1) can be modified to use a bigger dictionary:
xz --lzma2=preset=1,dict=32MiB foo.tar
With certain files, the above command may be faster than xz -6 while compressing significantly better.  However, it must be emphasized that only some files benefit from a big dictionary while keeping the CompCPU value low.  The most obvious situation, where a big dictionary can help a lot, is an archive containing very similar files of at least a few megabytes each.  The dictionary size has to be significantly bigger than any individual file to allow LZMA2 to take full advantage of the similarities between consecutive files.
If very high compressor and decompressor memory usage is fine, and the file being compressed is at least several hundred megabytes, it may be useful to use an even bigger dictionary than the 64 MiB that xz -9 would use:
xz -vv --lzma2=dict=192MiB big_foo.tar
Using -vv (--verbose --verbose) like in the above example can be useful to see the memory requirements of the compressor and decompressor. Remember that using a dictionary bigger than the size of the uncompressed file is waste of memory, so the above command isn't useful for small files.
Sometimes the compression time doesn't matter, but the decompressor memory usage has to be kept low e.g. to make it possible to decompress the file on an embedded system.  The following command uses -6e (-6 --extreme) as a base and sets the dictionary to only 64 KiB.  The resulting file can be decompressed with XZ Embedded (that's why there is --check=crc32) using about 100 KiB of memory.
xz --check=crc32 --lzma2=preset=6e,dict=64KiB foo
If you want to squeeze out as many bytes as possible, adjusting the number of literal context bits (lc) and number of position bits (pb) can sometimes help.  Adjusting the number of literal position bits (lp) might help too, but usually lc and pb are more important.  E.g. a source code archive contains mostly US-ASCII text, so something like the following might give slightly (like 0.1 %) smaller file than xz -6e (try also without lc=4):
xz --lzma2=preset=6e,pb=0,lc=4 source_code.tar
Using another filter together with LZMA2 can improve compression with certain file types.  E.g. to compress a x86-32 or x86-64 shared library using the x86 BCJ filter:
xz --x86 --lzma2 libfoo.so
Note that the order of the filter options is significant.  If --x86 is specified after --lzma2, xz will give an error, because there cannot be any filter after LZMA2, and also because the x86 BCJ filter cannot be used as the last filter in the chain.
The Delta filter together with LZMA2 can give good results with bitmap images.  It should usually beat PNG, which has a few more advanced filters than simple delta but uses Deflate for the actual compression.
The image has to be saved in uncompressed format, e.g. as uncompressed TIFF.  The distance parameter of the Delta filter is set to match the number of bytes per pixel in the image.  E.g. 24-bit RGB bitmap needs dist=3, and it is also good to pass pb=0 to LZMA2 to accommodate the three-byte alignment:
xz --delta=dist=3 --lzma2=pb=0 foo.tiff
If multiple images have been put into a single archive (e.g. .tar), the Delta filter will work on that too as long as all images have the same number of bytes per pixel.
xzdec(1), xzdiff(1), xzgrep(1), xzless(1), xzmore(1), gzip(1), bzip2(1), 7z(1)
XZ Utils: <https://tukaani.org/xz/> XZ Embedded: <https://tukaani.org/xz/embedded.html> LZMA SDK: <http://7-zip.org/sdk.html>
LSOF(1)                      General Commands Manual                     LSOF(1)
lsof - list open files
lsof [ -?abChlnNOPRtUvVX ] [ -A A ] [ -c c ] [ +c c ] [ +|-d d ] [ +|-D D ] [ +|-e s ] [ +|-E ] [ +|-f [cfgGn] ] [ -F [f] ] [ -g [s] ] [ -i [i] ] [ -k k ] [ -K k ] [ +|-L [l] ] [ +|-m m ] [ +|-M ] [ -o [o] ] [ -p s ] [ +|-r [t[m<fmt>]] ] [ -s [p:s] ] [ -S [t] ] [ -T [t] ] [ -u s ] [ +|-w ] [ -x [fl] ] [ -z [z] ] [ -Z [Z] ] [ -- ] [names]
Lsof revision 4.94.0 lists on its standard output file information about files opened by processes for the following UNIX dialects:
Apple Darwin 9 and Mac OS X 10.[567] FreeBSD 8.[234], 9.0 and 1[012].0 for AMD64-based systems Linux 2.1.72 and above for x86-based systems Solaris 9, 10 and 11
(See the DISTRIBUTION section of this manual page for information on how to obtain the latest lsof revision.)
An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.)  A specific file or all the files in a file system may be selected by path.
Instead of a formatted display, lsof will produce output that can be parsed by other programs.  See the -F, option description, and the OUTPUT FOR OTHER PROGRAMS section for more information.
In addition to producing a single output list, lsof will run in repeat mode.  In repeat mode it will produce output, delay, then repeat the output operation until stopped with an interrupt or quit signal.  See the +|-r [t[m<fmt>]] option description for more information.
In the absence of any options, lsof lists all open files belonging to all active processes.
If any list request option is specified, other list requests must be specifically requested - e.g., if -U is specified for the listing of UNIX socket files, NFS files won't be listed unless -N is also specified; or if a user list is specified with the -u option, UNIX domain socket files, belonging to users not in the list, won't be listed unless the -U option is also specified.
Normally list options that are specifically stated are ORed - i.e., specifying the -i option without an address and the -ufoo option produces a listing of all network files OR files belonging to processes owned by user ``foo''.  The exceptions are:
1) the `^' (negated) login name or user ID (UID), specified with the -u option;
2) the `^' (negated) process ID (PID), specified with the -p option;
3) the `^' (negated) process group ID (PGID), specified with the -g option;
4) the `^' (negated) command, specified with the -c option;
5) the (`^') negated TCP or UDP protocol state names, specified with the -s [p:s] option.
Since they represent exclusions, they are applied without ORing or ANDing and take effect before any other selection criteria are applied.
The -a option may be used to AND the selections.  For example, specifying -a, -U, and -ufoo produces a listing of only UNIX socket files that belong to processes owned by user ``foo''.
Caution: the -a option causes all list selection options to be ANDed; it can't be used to cause ANDing of selected pairs of selection options by placing it between them, even though its placement there is acceptable. Wherever -a is placed, it causes the ANDing of all selection options.
Items of the same selection set - command names, file descriptors, network addresses, process identifiers, user identifiers, zone names, security contexts - are joined in a single ORed set and applied before the result participates in ANDing.  Thus, for example, specifying -i@aaa.bbb, -i@ccc.ddd, -a, and -ufff,ggg will select the listing of files that belong to either login ``fff'' OR ``ggg'' AND have network connections to either host aaa.bbb OR ccc.ddd.
Options may be grouped together following a single prefix -- e.g., the option set ``-a -b -C'' may be stated as -abC.  However, since values are optional following +|-f, -F, -g, -i, +|-L, -o, +|-r, -s, -S, -T, -x and -z.  when you have no values for them be careful that the following character isn't ambiguous.  For example, -Fn might represent the -F and -n options, or it might represent the n field identifier character following the -F option.  When ambiguity is possible, start a new option with a `-' character - e.g., ``-F -n''.  If the next option is a file name, follow the possibly ambiguous option with ``--'' - e.g., ``-F -- name''.
Either the `+' or the `-' prefix may be applied to a group of options. Options that don't take on separate meanings for each prefix - e.g., -i - may be grouped under either prefix.  Thus, for example, ``+M -i'' may be stated as ``+Mi'' and the group means the same as the separate options. Be careful of prefix grouping when one or more options in the group does take on separate meanings under different prefixes - e.g., +|-M; ``-iM'' is not the same request as ``-i +M''.  When in doubt, use separate options with appropriate prefixes.
-? -h    These two equivalent options select a usage (help) output list. Lsof displays a shortened form of this output when it detects an error in the options supplied to it, after it has displayed messages explaining each error.  (Escape the `?' character as your shell requires.)
-a       causes list selection options to be ANDed, as described above.
-A A     is available on systems configured for AFS whose AFS kernel code is implemented via dynamic modules.  It allows the lsof user to specify A as an alternate name list file where the kernel addresses of the dynamic modules might be found.  See the lsof FAQ (The FAQ section gives its location.)  for more information about dynamic modules, their symbols, and how they affect lsof.
-b       causes lsof to avoid kernel functions that might block - lstat(2), readlink(2), and stat(2).
See the BLOCKS AND TIMEOUTS and AVOIDING KERNEL BLOCKS sections for information on using this option.
-c c     selects the listing of files for processes executing the command that begins with the characters of c.  Multiple commands may be specified, using multiple -c options.  They are joined in a single ORed set before participating in AND option selection.
If c begins with a `^', then the following characters specify a command name whose processes are to be ignored (excluded.)
If c begins and ends with a slash ('/'), the characters between the slashes are interpreted as a regular expression.  Shell meta-characters in the regular expression must be quoted to prevent their interpretation by the shell.  The closing slash may be followed by these modifiers:
b    the regular expression is a basic one. i    ignore the case of letters. x    the regular expression is an extended one (default).
See the lsof FAQ (The FAQ section gives its location.)  for more information on basic and extended regular expressions.
The simple command specification is tested first.  If that test fails, the command regular expression is applied.  If the simple command test succeeds, the command regular expression test isn't made.  This may result in ``no command found for regex:'' messages when lsof's -V option is specified.
+c w     defines the maximum number of initial characters of the name, supplied by the UNIX dialect, of the UNIX command associated with a process to be printed in the COMMAND column.  (The lsof default is nine.)
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.  Often dialects limit the number of characters supplied in those sources.  For example, Linux 2.4.27 and Solaris 9 both limit command name length to 16 characters.
If w is zero ('0'), all command characters supplied to lsof by the UNIX dialect will be printed.
If w is less than the length of the column title, ``COMMAND'', it will be raised to that length.
-C       disables the reporting of any path name components from the kernel's name cache.  See the KERNEL NAME CACHE section for more information.
+d s     causes lsof to search for all open instances of directory s and the files and directories it contains at its top level.  +d does NOT descend the directory tree, rooted at s.  The +D D option may be used to request a full-descent directory tree search, rooted at directory D.
Processing of the +d option does not follow symbolic links within s unless the -x or -x  l option is also specified.  Nor does it search for open files on file system mount points on subdirectories of s unless the -x or -x  f option is also specified.
Note: the authority of the user of this option limits it to searching for files that the user has permission to examine with the system stat(2) function.
-d s     specifies a list of file descriptors (FDs) to exclude from or include in the output listing.  The file descriptors are specified in the comma-separated set s - e.g., ``cwd,1,3'', ``^6,^2''.  (There should be no spaces in the set.)
The list is an exclusion list if all entries of the set begin with `^'.  It is an inclusion list if no entry begins with `^'. Mixed lists are not permitted.
A file descriptor number range may be in the set as long as neither member is empty, both members are numbers, and the ending member is larger than the starting one - e.g., ``0-7'' or ``3-10''.  Ranges may be specified for exclusion if they have the `^' prefix - e.g., ``^0-7'' excludes all file descriptors 0 through 7.
Multiple file descriptor numbers are joined in a single ORed set before participating in AND option selection.
When there are exclusion and inclusion members in the set, lsof reports them as errors and exits with a non-zero return code.
See the description of File Descriptor (FD) output values in the OUTPUT section for more information on file descriptor names.
fd is a pseudo file descriptor name for specifying the whole range of possible file descriptor numbers.  fd does not appear in FD column of output.
+D D     causes lsof to search for all open instances of directory D and all the files and directories it contains to its complete depth.
Processing of the +D option does not follow symbolic links within D unless the -x or -x  l option is also specified.  Nor does it search for open files on file system mount points on subdirectories of D unless the -x or -x  f option is also specified.
Further note: lsof may process this option slowly and require a large amount of dynamic memory to do it.  This is because it must descend the entire directory tree, rooted at D, calling stat(2) for each file and directory, building a list of all the files it finds, and searching that list for a match with every open file.  When directory D is large, these steps can take a long time, so use this option prudently.
-D D     directs lsof's use of the device cache file.  The use of this option is sometimes restricted.  See the DEVICE CACHE FILE section and the sections that follow it for more information on this option.
-D must be followed by a function letter; the function letter may optionally be followed by a path name.  Lsof recognizes these function letters:
? - report device cache file paths b - build the device cache file i - ignore the device cache file r - read the device cache file u - read and update the device cache file
The b, r, and u functions, accompanied by a path name, are sometimes restricted.  When these functions are restricted, they will not appear in the description of the -D option that accompanies -h or -?  option output.  See the DEVICE CACHE FILE section and the sections that follow it for more information on these functions and when they're restricted.
The ?  function reports the read-only and write paths that lsof can use for the device cache file, the names of any environment variables whose values lsof will examine when forming the device cache file path, and the format for the personal device cache file path.  (Escape the `?' character as your shell requires.)
When available, the b, r, and u functions may be followed by the device cache file's path.  The standard default is .lsof_hostname in the home directory of the real user ID that executes lsof, but this could have been changed when lsof was configured and compiled.  (The output of the -h and -?  options show the current default prefix - e.g., ``.lsof''.)  The suffix, hostname, is the first component of the host's name returned by gethostname(2).
When available, the b function directs lsof to build a new device cache file at the default or specified path.
The i function directs lsof to ignore the default device cache file and obtain its information about devices via direct calls to the kernel.
The r function directs lsof to read the device cache at the default or specified path, but prevents it from creating a new device cache file when none exists or the existing one is improperly structured.  The r function, when specified without a path name, prevents lsof from updating an incorrect or outdated device cache file, or creating a new one in its place.  The r function is always available when it is specified without a path name argument; it may be restricted by the permissions of the lsof process.
When available, the u function directs lsof to read the device cache file at the default or specified path, if possible, and to rebuild it, if necessary.  This is the default device cache file function when no -D option has been specified.
+|-e s   exempts the file system whose path name is s from being subjected to kernel function calls that might block.  The +e option exempts stat(2), lstat(2) and most readlink(2) kernel function calls.  The -e option exempts only stat(2) and lstat(2) kernel function calls.  Multiple file systems may be specified with separate +|-e specifications and each may have readlink(2) calls exempted or not.
This option is currently implemented only for Linux.
CAUTION: this option can easily be mis-applied to other than the file system of interest, because it uses path name rather than the more reliable device and inode numbers.  (Device and inode numbers are acquired via the potentially blocking stat(2) kernel call and are thus not available, but see the +|-m m option as a possible alternative way to supply device numbers.)  Use this option with great care and fully specify the path name of the file system to be exempted.
When open files on exempted file systems are reported, it may not be possible to obtain all their information.  Therefore, some information columns will be blank, the characters ``UNKN'' preface the values in the TYPE column, and the applicable exemption option is added in parentheses to the end of the NAME column.  (Some device number information might be made available via the +|-m m option.)
+|-E     +E specifies that Linux pipe, Linux UNIX socket, Linux INET(6) socket closed in a local host, Linux pseudoterminal files, POSIX Message Queueue implementation in Linux, and Linux eventfd should be displayed with endpoint information and the files of the endpoints should also be displayed.
Note 1: UNIX socket file endpoint information is only available when the compile flags line of -v output contains HASUXSOCKEPT, and psudoterminal endpoint information is only available when the compile flags line contains HASPTYEPT.
Note 2: POSIX Message Queue file endpoint information is only available when mqueue file system is mounted.
Pipe endpoint information is displayed in the NAME column in the form ``PID,cmd,FDmode'', where PID is the endpoint process ID; cmd is the endpoint process command; FD is the endpoint file's descriptor; and mode is the endpoint file's access mode.
Pseudoterminal endpoint information is displayed in the NAME column as ``->/dev/ptsmin PID,cmd,FDmode'' or ``PID,cmd,FDmode''.  The first form is for a master device; the second, for a slave device.  min is a slave device's minor device number; and PID, cmd, FD and mode are the same as with pipe endpoint information.  Note: psudoterminal endpoint information is only available when the compile flags line of -V output contains HASPTYEPT. In addition, this feature works on Linux kernels above 4.13.0.
UNIX socket file endpoint information is displayed in the NAME column in the form ``type=TYPE ->INO=INODE PID,cmd,FDmode'', where TYPE is the socket type; INODE is the i-node number of the connected socket; and PID, cmd, FD and mode are the same as with pipe endpoint information.  Note: UNIX socket file endpoint information is available only when the compile flags line of -v output contains HASUXSOCKEPT.
INET socket file endpoint information is inserted to the value at the NAME column in th form PID, cmd, FD and mode are the same as with pipe endpoint information. The endpoint information is available only if the socket is used for local IPC; both endpoints bind to the same local IPv4 or IPv6 address.
POSIX Message Queue file endpoint information is displayed in the NAME column in the same form as that of pipe.
eventfd endpoint information is displayed in the NAME column in the same form as that of pipe. This feature works on Linux kernels above 5.2.0.
Multiple occurrences of this information can appear in a file's NAME column.
-E specfies that endpoint supported files should be displayed with endpoint information, but not the files of the endpoints.
+|-f [cfgGn] f by itself clarifies how path name arguments are to be interpreted.  When followed by c, f, g, G, or n in any combination it specifies that the listing of kernel file structure information is to be enabled (`+') or inhibited (`-').
Normally a path name argument is taken to be a file system name if it matches a mounted-on directory name reported by mount(8), or if it represents a block device, named in the mount output and associated with a mounted directory name.  When +f is specified, all path name arguments will be taken to be file system names, and lsof will complain if any are not.  This can be useful, for example, when the file system name (mounted-on device) isn't a block device.  This happens for some CD-ROM file systems.
When -f is specified by itself, all path name arguments will be taken to be simple files.  Thus, for example, the ``-f -- /'' arguments direct lsof to search for open files with a `/' path name, not all open files in the `/' (root) file system.
Be careful to make sure +f and -f are properly terminated and aren't followed by a character (e.g., of the file or file system name) that might be taken as a parameter.  For example, use ``--'' after +f and -f as in these examples.
$ lsof +f -- /file/system/name $ lsof -f -- /file/name
The listing of information from kernel file structures, requested with the +f [cfgGn] option form, is normally inhibited, and is not available in whole or part for some dialects - e.g., /proc-based Linux kernels below 2.6.22.  When the prefix to f is a plus sign (`+'), these characters request file structure information:
c    file structure use count (not Linux) f    file structure address (not Linux) g    file flag abbreviations (Linux 2.6.22 and up)
Abbrev.   Flag in C code (see open(2))
W         O_WRONLY RW        O_RDWR CR        O_CREAT EXCL      O_EXCL NTTY      O_NOCTTY TR        O_TRUNC AP        O_APPEND ND        O_NDELAY SYN       O_SYNC ASYN      O_ASYNC DIR       O_DIRECT DTY       O_DIRECTORY NFLK      O_NOFOLLOW NATM      O_NOATIME DSYN      O_DSYNC RSYN      O_RSYNC LG        O_LARGEFILE CX        O_CLOEXEC TMPF      O_TMPFILE
G    file flags in hexadecimal (Linux 2.6.22 and up) n    file structure node address (not Linux)
When the prefix is minus (`-') the same characters disable the listing of the indicated values.
File structure addresses, use counts, flags, and node addresses may be used to detect more readily identical files inherited by child processes and identical files in use by different processes.  Lsof column output can be sorted by output columns holding the values and listed to identify identical file use, or lsof field output can be parsed by an AWK or Perl post-filter script, or by a C program.
-F f     specifies a character list, f, that selects the fields to be output for processing by another program, and the character that terminates each output field.  Each field to be output is specified with a single character in f.  The field terminator defaults to NL, but may be changed to NUL (000).  See the OUTPUT FOR OTHER PROGRAMS section for a description of the field identification characters and the field output process.
When the field selection character list is empty, all standard fields are selected (except the raw device field, security context and zone field for compatibility reasons) and the NL field terminator is used.
When the field selection character list contains only a zero (`0'), all fields are selected (except the raw device field for compatibility reasons) and the NUL terminator character is used.
Other combinations of fields and their associated field terminator character must be set with explicit entries in f, as described in the OUTPUT FOR OTHER PROGRAMS section.
When a field selection character identifies an item lsof does not normally list - e.g., PPID, selected with -R - specification of the field character - e.g., ``-FR'' - also selects the listing of the item.
When the field selection character list contains the single character `?', lsof will display a help list of the field identification characters.  (Escape the `?' character as your shell requires.)
-g [s]   excludes or selects the listing of files for the processes whose optional process group IDentification (PGID) numbers are in the comma-separated set s - e.g., ``123'' or ``123,^456''.  (There should be no spaces in the set.)
PGID numbers that begin with `^' (negation) represent exclusions.
Multiple PGID numbers are joined in a single ORed set before participating in AND option selection.  However, PGID exclusions are applied without ORing or ANDing and take effect before other selection criteria are applied.
The -g option also enables the output display of PGID numbers. When specified without a PGID set that's all it does.
-i [i]   selects the listing of files any of whose Internet address matches the address specified in i.  If no address is specified, this option selects the listing of all Internet and x.25 (HP-UX) network files.
If -i4 or -i6 is specified with no following address, only files of the indicated IP version, IPv4 or IPv6, are displayed.  (An IPv6 specification may be used only if the dialects supports IPv6, as indicated by ``[46]'' and ``IPv[46]'' in lsof's -h or -?  output.)  Sequentially specifying -i4, followed by -i6 is the same as specifying -i, and vice-versa.  Specifying -i4, or -i6 after -i is the same as specifying -i4 or -i6 by itself.
Multiple addresses (up to a limit of 100) may be specified with multiple -i options.  (A port number or service name range is counted as one address.)  They are joined in a single ORed set before participating in AND option selection.
An Internet address is specified in the form (Items in square brackets are optional.):
[46][protocol][@hostname|hostaddr][:service|port]
where: 46 specifies the IP version, IPv4 or IPv6 that applies to the following address. '6' may be be specified only if the UNIX dialect supports IPv6.  If neither '4' nor '6' is specified, the following address applies to all IP versions. protocol is a protocol name - TCP, UDP hostname is an Internet host name.  Unless a specific IP version is specified, open network files associated with host names of all versions will be selected. hostaddr is a numeric Internet IPv4 address in dot form; or an IPv6 numeric address in colon form, enclosed in brackets, if the UNIX dialect supports IPv6.  When an IP version is selected, only its numeric addresses may be specified. service is an /etc/services name - e.g., smtp - or a list of them. port is a port number, or a list of them.
IPv6 options may be used only if the UNIX dialect supports IPv6. To see if the dialect supports IPv6, run lsof and specify the -h or -?  (help) option.  If the displayed description of the -i option contains ``[46]'' and ``IPv[46]'', IPv6 is supported.
IPv4 host names and addresses may not be specified if network file selection is limited to IPv6 with -i 6.  IPv6 host names and addresses may not be specified if network file selection is limited to IPv4 with -i 4.  When an open IPv4 network file's address is mapped in an IPv6 address, the open file's type will be IPv6, not IPv4, and its display will be selected by '6', not '4'.
At least one address component - 4, 6, protocol, hostname, hostaddr, or service - must be supplied.  The `@' character, leading the host specification, is always required; as is the `:', leading the port specification.  Specify either hostname or hostaddr.  Specify either service name list or port number list. If a service name list is specified, the protocol may also need to be specified if the TCP, UDP and UDPLITE port numbers for the service name are different.  Use any case - lower or upper - for protocol.
Service names and port numbers may be combined in a list whose entries are separated by commas and whose numeric range entries are separated by minus signs.  There may be no embedded spaces, and all service names must belong to the specified protocol. Since service names may contain embedded minus signs, the starting entry of a range can't be a service name; it can be a port number, however.
Here are some sample addresses:
-i6 - IPv6 only TCP:25 - TCP and port 25 @1.2.3.4 - Internet IPv4 host address 1.2.3.4 @[3ffe:1ebc::1]:1234 - Internet IPv6 host address 3ffe:1ebc::1, port 1234 UDP:who - UDP who service port TCP@lsof.itap:513 - TCP, port 513 and host name lsof.itap tcp@foo:1-10,smtp,99 - TCP, ports 1 through 10, service name smtp, port 99, host name foo tcp@bar:1-smtp - TCP, ports 1 through smtp, host bar :time - either TCP, UDP or UDPLITE time service port
-K k     selects the listing of tasks (threads) of processes, on dialects where task (thread) reporting is supported.  (If help output - i.e., the output of the -h or -?  options - shows this option, then task (thread) reporting is supported by the dialect.)
If -K is followed by a value, k, it must be ``i''.  That causes lsof to ignore tasks, particularly in the default, list-everything case when no other options are specified.
When -K and -a are both specified on Linux, and the tasks of a main process are selected by other options, the main process will also be listed as though it were a task, but without a task ID.  (See the description of the TID column in the OUTPUT section.)
Where the FreeBSD version supports threads, all threads will be listed with their IDs.
In general threads and tasks inherit the files of the caller, but may close some and open others, so lsof always reports all the open files of threads and tasks.
-k k     specifies a kernel name list file, k, in place of /vmunix, /mach, etc.  -k is not available under AIX on the IBM RISC/System 6000.
-l       inhibits the conversion of user ID numbers to login names.  It is also useful when login name lookup is working improperly or slowly.
+|-L [l] enables (`+') or disables (`-') the listing of file link counts, where they are available - e.g., they aren't available for sockets, or most FIFOs and pipes.
When +L is specified without a following number, all link counts will be listed.  When -L is specified (the default), no link counts will be listed.
When +L is followed by a number, only files having a link count less than that number will be listed.  (No number may follow -L.)  A specification of the form ``+L1'' will select open files that have been unlinked.  A specification of the form ``+aL1 <file_system>'' will select unlinked open files on the specified file system.
For other link count comparisons, use field output (-F) and a post-processing script or program.
+|-m m   specifies an alternate kernel memory file or activates mount table supplement processing.
The option form -m m specifies a kernel memory file, m, in place of /dev/kmem or /dev/mem - e.g., a crash dump file.
The option form +m requests that a mount supplement file be written to the standard output file.  All other options are silently ignored.
There will be a line in the mount supplement file for each mounted file system, containing the mounted file system directory, followed by a single space, followed by the device number in hexadecimal "0x" format - e.g.,
/ 0x801
Lsof can use the mount supplement file to get device numbers for file systems when it can't get them via stat(2) or lstat(2).
The option form +m m identifies m as a mount supplement file.
Note: the +m and +m m options are not available for all supported dialects.  Check the output of lsof's -h or -? options to see if the +m and +m m options are available.
+|-M     Enables (+) or disables (-) the reporting of portmapper registrations for local TCP, UDP and UDPLITE ports, where port mapping is supported.  (See the last paragraph of this option description for information about where portmapper registration reporting is supported.)
The default reporting mode is set by the lsof builder with the HASPMAPENABLED #define in the dialect's machine.h header file; lsof is distributed with the HASPMAPENABLED #define deactivated, so portmapper reporting is disabled by default and must be requested with +M.  Specifying lsof's -h or -?  option will report the default mode.  Disabling portmapper registration when it is already disabled or enabling it when already enabled is acceptable.  When portmapper registration reporting is enabled, lsof displays the portmapper registration (if any) for local TCP, UDP or UDPLITE ports in square brackets immediately following the port numbers or service names - e.g., ``:1234[name]'' or ``:name[100083]''.  The registration information may be a name or number, depending on what the registering program supplied to the portmapper when it registered the port.
When portmapper registration reporting is enabled, lsof may run a little more slowly or even become blocked when access to the portmapper becomes congested or stopped.  Reverse the reporting mode to determine if portmapper registration reporting is slowing or blocking lsof.
For purposes of portmapper registration reporting lsof considers a TCP, UDP or UDPLITE port local if: it is found in the local part of its containing kernel structure; or if it is located in the foreign part of its containing kernel structure and the local and foreign Internet addresses are the same; or if it is located in the foreign part of its containing kernel structure and the foreign Internet address is INADDR_LOOPBACK (127.0.0.1). This rule may make lsof ignore some foreign ports on machines with multiple interfaces when the foreign Internet address is on a different interface from the local one.
See the lsof FAQ (The FAQ section gives its location.)  for further discussion of portmapper registration reporting issues.
Portmapper registration reporting is supported only on dialects that have RPC header files.  (Some Linux distributions with GlibC 2.14 do not have them.)  When portmapper registration reporting is supported, the -h or -?  help output will show the +|-M option.
-n       inhibits the conversion of network numbers to host names for network files.  Inhibiting conversion may make lsof run faster. It is also useful when host name lookup is not working properly.
-N       selects the listing of NFS files.
-o       directs lsof to display file offset at all times.  It causes the SIZE/OFF output column title to be changed to OFFSET.  Note: on some UNIX dialects lsof can't obtain accurate or consistent file offset information from its kernel data sources, sometimes just for particular kinds of files (e.g., socket files.)  Consult the lsof FAQ (The FAQ section gives its location.)  for more information.
The -o and -s options are mutually exclusive; they can't both be specified.  When neither is specified, lsof displays whatever value - size or offset - is appropriate and available for the type of the file.
-o o     defines the number of decimal digits (o) to be printed after the ``0t'' for a file offset before the form is switched to ``0x...''.  An o value of zero (unlimited) directs lsof to use the ``0t'' form for all offset output.
This option does NOT direct lsof to display offset at all times; specify -o (without a trailing number) to do that.  -o o only specifies the number of digits after ``0t'' in either mixed size and offset or offset-only output.  Thus, for example, to direct lsof to display offset at all times with a decimal digit count of 10, use:
-o -o 10 or -oo10
The default number of digits allowed after ``0t'' is normally 8, but may have been changed by the lsof builder.  Consult the description of the -o o option in the output of the -h or -? option to determine the default that is in effect.
-O       directs lsof to bypass the strategy it uses to avoid being blocked by some kernel operations - i.e., doing them in forked child processes.  See the BLOCKS AND TIMEOUTS and AVOIDING KERNEL BLOCKS sections for more information on kernel operations that may block lsof.
While use of this option will reduce lsof startup overhead, it may also cause lsof to hang when the kernel doesn't respond to a function.  Use this option cautiously.
-p s     excludes or selects the listing of files for the processes whose optional process IDentification (PID) numbers are in the comma-separated set s - e.g., ``123'' or ``123,^456''.  (There should be no spaces in the set.)
PID numbers that begin with `^' (negation) represent exclusions.
Multiple process ID numbers are joined in a single ORed set before participating in AND option selection.  However, PID exclusions are applied without ORing or ANDing and take effect before other selection criteria are applied.
-P       inhibits the conversion of port numbers to port names for network files.  Inhibiting the conversion may make lsof run a little faster.  It is also useful when port name lookup is not working properly.
+|-r [t[c<N>][m<fmt>]] puts lsof in repeat mode.  There lsof lists open files as selected by other options, delays t seconds (default fifteen), then repeats the listing, delaying and listing repetitively until stopped by a condition defined by the prefix to the option.
If the prefix is a `-', repeat mode is endless.  Lsof must be terminated with an interrupt or quit signal.  `c<N>' is for specifying the limits of repeating; if the number of iterations reaches at `<N>', Lsof stops itself.
If the prefix is `+', repeat mode will end the first cycle no open files are listed - and of course when lsof is stopped with an interrupt or quit signal.  When repeat mode ends because no files are listed, the process exit code will be zero if any open files were ever listed; one, if none were ever listed.
Lsof marks the end of each listing: if field output is in progress (the -F, option has been specified), the default marker is `m'; otherwise the default marker is ``========''.  The marker is followed by a NL character.
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 strftime(3) function, when both it and the localtime(3) function are available in the dialect's C library.  Consult the strftime(3) documentation for what may appear in its format specification.  Note that when field output is requested with the -F option, <fmt> cannot contain the NL format, ``%n''.  Note also that when <fmt> contains spaces or other characters that affect the shell's interpretation of arguments, <fmt> must be quoted appropriately.
Repeat mode reduces lsof startup overhead, so it is more efficient to use this mode than to call lsof repetitively from a shell script, for example.
To use repeat mode most efficiently, accompany +|-r with specification of other lsof selection options, so the amount of kernel memory access lsof does will be kept to a minimum. Options that filter at the process level - e.g., -c, -g, -p, -u - are the most efficient selectors.
Repeat mode is useful when coupled with field output (see the -F, option description) and a supervising awk or Perl script, or a C program.
-R       directs lsof to list the Parent Process IDentification number in the PPID column.
-s [p:s] s alone directs lsof to display file size at all times.  It causes the SIZE/OFF output column title to be changed to SIZE. If the file does not have a size, nothing is displayed.
The optional -s p:s form is available only for selected dialects, and only when the -h or -?  help output lists it.
When the optional form is available, the s may be followed by a protocol name (p), either TCP or UDP, a colon (`:') and a comma-separated protocol state name list, the option causes open TCP and UDP files to be excluded if their state name(s) are in the list (s) preceded by a `^'; or included if their name(s) are not preceded by a `^'.
Dialects that support this option may support only one protocol. When an unsupported protocol is specified, a message will be displayed indicating state names for the protocol are unavailable.
When an inclusion list is defined, only network files with state names in the list will be present in the lsof output.  Thus, specifying one state name means that only network files with that lone state name will be listed.
Case is unimportant in the protocol or state names, but there may be no spaces and the colon (`:') separating the protocol name (p) and the state name list (s) is required.
If only TCP and UDP files are to be listed, as controlled by the specified exclusions and inclusions, the -i option must be specified, too.  If only a single protocol's files are to be listed, add its name as an argument to the -i option.
For example, to list only network files with TCP state LISTEN, use:
-iTCP -sTCP:LISTEN
Or, for example, to list network files with all UDP states except Idle, use:
-iUDP -sUDP:^Idle
State names vary with UNIX dialects, so it's not possible to provide a complete list.  Some common TCP state names are: CLOSED, IDLE, BOUND, LISTEN, ESTABLISHED, SYN_SENT, SYN_RCDV, ESTABLISHED, CLOSE_WAIT, FIN_WAIT1, CLOSING, LAST_ACK, FIN_WAIT_2, and TIME_WAIT.  Two common UDP state names are Unbound and Idle.
See the lsof FAQ (The FAQ section gives its location.)  for more information on how to use protocol state exclusion and inclusion, including examples.
The -o (without a following decimal digit count) and -s option (without a following protocol and state name list) are mutually exclusive; they can't both be specified.  When neither is specified, lsof displays whatever value - size or offset - is appropriate and available for the type of file.
Since some types of files don't have true sizes - sockets, FIFOs, pipes, etc. - lsof displays for their sizes the content amounts in their associated kernel buffers, if possible.
-S [t]   specifies an optional time-out seconds value for kernel functions - lstat(2), readlink(2), and stat(2) - that might otherwise deadlock.  The minimum for t is two; the default, fifteen; when no value is specified, the default is used.
See the BLOCKS AND TIMEOUTS section for more information.
-T [t]   controls the reporting of some TCP/TPI information, also reported by netstat(1), following the network addresses.  In normal output the information appears in parentheses, each item except TCP or TPI state name identified by a keyword, followed by `=', separated from others by a single space:
<TCP or TPI state name> QR=<read queue length> QS=<send queue length> SO=<socket options and values> SS=<socket states> TF=<TCP flags and values> WR=<window read length> WW=<window write length>
Not all values are reported for all UNIX dialects.  Items values (when available) are reported after the item name and '='.
When the field output mode is in effect (See OUTPUT FOR OTHER PROGRAMS.)  each item appears as a field with a `T' leading character.
-T with no following key characters disables TCP/TPI information reporting.
-T with following characters selects the reporting of specific TCP/TPI information:
f    selects reporting of socket options, states and values, and TCP flags and values. q    selects queue length reporting. s    selects connection state reporting. w    selects window size reporting.
Not all selections are enabled for some UNIX dialects.  State may be selected for all dialects and is reported by default. The -h or -?  help output for the -T option will show what selections may be used with the UNIX dialect.
When -T is used to select information - i.e., it is followed by one or more selection characters - the displaying of state is disabled by default, and it must be explicitly selected again in the characters following -T.  (In effect, then, the default is equivalent to -Ts.)  For example, if queue lengths and state are desired, use -Tqs.
Socket options, socket states, some socket values, TCP flags and one TCP value may be reported (when available in the UNIX dialect) in the form of the names that commonly appear after SO_, so_, SS_, TCP_  and TF_ in the dialect's header files - most often <sys/socket.h>, <sys/socketvar.h> and <netinet/tcp_var.h>.  Consult those header files for the meaning of the flags, options, states and values.
``SO='' precedes socket options and values; ``SS='', socket states; and ``TF='', TCP flags and values.
If a flag or option has a value, the value will follow an '=' and the name -- e.g., ``SO=LINGER=5'', ``SO=QLIM=5'', ``TF=MSS=512''.  The following seven values may be reported:
Name Reported  Description (Common Symbol)
KEEPALIVE keep alive time (SO_KEEPALIVE) LINGER    linger time (SO_LINGER) MSS       maximum segment size (TCP_MAXSEG) PQLEN          partial listen queue connections QLEN      established listen queue connections QLIM      established listen queue limit RCVBUF    receive buffer length (SO_RCVBUF) SNDBUF    send buffer length (SO_SNDBUF)
Details on what socket options and values, socket states, and TCP flags and values may be displayed for particular UNIX dialects may be found in the answer to the ``Why doesn't lsof report socket options, socket states, and TCP flags and values for my dialect?'' and ``Why doesn't lsof report the partial listen queue connection count for my dialect?''  questions in the lsof FAQ (The FAQ section gives its location.)  On Linux this option also prints the state of UNIX domain sockets.
-t       produce terse output comprising only process identifiers (without a header), so that it is easy to use programmatically. e.g.
# reload anything using old SSL lsof -t /lib/*/libssl.so.* | xargs -r kill -HUP
# get list of processes and then iterate over them (Bash only) mapfile -t pids < <( lsof -wt /var/log/your.log ) for pid in "${pids[@]}" ; do your_command -p "$pid" done
The -t option implies the -w option.