1 //po4a: entry man manual
3 Copyright 2021 Red Hat, Inc.
5 This file may be copied under the terms of the GNU Public License.
9 :man manual: User Commands
10 :man source: util-linux {release-version}
17 lsfd - list file descriptors
25 *lsfd* is intended to be a modern replacement for *lsof*(8) on Linux systems.
26 Unlike *lsof*, *lsfd* is specialized to Linux kernel; it supports Linux
27 specific features like namespaces with simpler code. *lsfd* is not a
28 drop-in replacement for *lsof*; they are different in the command line
29 interface and output formats.
31 The default output is subject to change. So whenever possible, you should avoid using
32 default outputs in your scripts. Always explicitly define expected columns by using
33 *--output* _columns-list_ in environments where a stable output is required.
35 *lsfd* uses Libsmartcols for output formatting and filtering. See the description of *--output*
36 option for customizing the output format, and *--filter* option for filtering. Use *lsfd --help*
37 to get a list of all available columns.
42 List in threads level.
45 Use JSON output format.
47 *-n*, *--noheadings*::
50 *-o*, *--output* _list_::
51 Specify which output columns to print. See the *OUTPUT COLUMNS*
52 section for details of available columns.
54 The default list of columns may be extended if _list_ is specified in
55 the format +_list_ (e.g., *lsfd -o +DELETED*).
58 Use raw output format.
61 Don't truncate text in columns.
63 *-p*, *--pid* _pids_::
64 Collect information only for specified processes.
65 _pids_ is a list of pids. A comma or whitespaces can be used as separators.
66 You can use this option with *pidof*(1). See *FILTER EXAMPLES*.
68 Both *-Q* option with an expression including PID, e.g. -Q (PID == 1),
69 and *-p* option, e.g. -p 1, may print the same output but using *-p*
70 option is much more efficient because *-p* option works at a much earlier
71 stage of processing than the *-Q* option.
73 *-i*[4|6], *--inet*[=4|=6]::
74 List only IPv4 sockets and/or IPv6 sockets.
76 *-Q*, *--filter* _expr_::
77 Print only the files matching the condition represented by the _expr_.
78 See also *FILTER EXAMPLES*.
80 *-C*, *--counter* __label__:__filter_expr__::
81 Define a custom counter used in *--summary* output. *lsfd* makes a
82 counter named _label_. During collect information, *lsfd* counts files
83 matching _filter_expr_, and stores the counted number to the
84 counter named _label_. *lsfd* applies filters defined with *--filter*
85 options before counting; files excluded by the filters are not counted.
87 See *FILTER EXPRESSION* about _filter_expr_.
88 _label_ should not include `{` nor `:`. You can define multiple
89 counters by specifying this option multiple times.
91 See also *COUNTER EXAMPLES*.
93 *--summary*[=_when_]::
94 This option controls summary lines output. The optional argument _when_
95 can be *only*, *append* or *never*. If the _when_ argument is omitted,
96 it defaults to *only*.
98 The summary reports counters. A counter consists of a label and an
99 integer value. *--counter* is the option for defining a counter. If
100 a user defines no counter, *lsfd* uses the definitions of pre-defined
101 built-in counters (default counters) to make the summary output.
103 CAUTION{colon} Using *--summary* and *--json* may make the output broken. Only combining *--summary*=*only* and *--json* is valid.
104 //TRANSLATORS: Keep {colon} untranslated.
107 Dump the internal data structure for the filter and exit. This is useful
108 only for *lsfd* developers.
111 Dump the definition of counters used in *--summary* output.
113 *-H*, *--list-columns*::
114 List available columns that you can specify at *--output* option.
116 include::man-common/help-version.adoc[]
120 Each column has a type. Types are surround by < and >.
122 //TRANSLATORS: Keep {colon} untranslated.
123 CAUTION{colon} The names and types of columns are not stable yet.
124 They may be changed in the future releases.
126 AINODECLASS <``string``>::
127 Class of anonymous inode.
130 Association between file and process.
132 BLKDRV <``string``>::
133 Block device driver name resolved by `/proc/devices`.
135 BPF-PROG.ID <``number``>::
138 BPF-PROG.TYPE <``string``>::
139 Decoded name of bpf program type.
141 BPF-PROG.TYPE.RAW <``number``>::
142 Bpf program type (raw).
144 CHRDRV <``string``>::
145 Character device driver name resolved by `/proc/devices`.
147 COMMAND <``string``>::
148 Command of the process opening the file.
150 DELETED <``boolean``>::
151 Reachability from the file system.
154 ID of the device containing the file.
156 DEVTYPE <``string``>::
157 Device type (`blk`, `char`, or `nodev`).
159 ENDPOINT <``string``>::
160 IPC endpoints information communicated with the fd.
162 *lsfd* collects endpoints within the processes that
163 *lsfd* scans; *lsfd* may miss some endpoints
164 if you limits the processes with *-p* option.
166 The format of the column depends on the object associated
171 _PID_,_COMMAND_,_ASSOC_[-r][-w]
173 The last characters ([-r][-w]) represents the read and/or
174 write mode of the endpoint.
177 _PID_,_COMMAND_,_ASSOC_
179 EVENTFD.ID <``number``>::
182 EVENTPOLL.TFDS <``string``>::
183 File descriptors targeted by the eventpoll file.
186 File descriptor for the file.
189 Flags specified when opening the file.
192 User ID number of the file's owner.
194 INET.LADDR <``string``>::
197 INET.RADDR <``string``>::
200 INET6.LADDR <``string``>::
203 INET6.RADDR <``string``>::
209 INOTIFY.INODES <``string``>::
210 Cooked version of INOTIFY.INODES.RAW.
211 The format of the element is
212 _inode-number_,_source-of-inode_.
214 INOTIFY.INODES.RAW <``string``>::
215 List of monitoring inodes. The format of the element
216 is _inode-number_,_device-major_:_device-minor_.
220 // It seems that the manpage backend of asciidoctor has limitations
221 // about emitting text with nested face specifications like:
225 // Not only u but also p is decorated with underline.
227 Raw file name extracted from
228 from ``/proc/``_pid_``/fd/``_fd_ or ``/proc/``_pid_``/map_files/``_region_.
230 KTHREAD <``boolean``>::
231 Whether the process is a kernel thread or not.
233 MAJ:MIN <``string``>::
234 Device ID for special, or ID of device containing file.
236 MAPLEN <``number``>::
237 Length of file mapping (in page).
239 MISCDEV <``string``>::
240 Misc character device name resolved by `/proc/misc`.
249 Cooked version of KNAME. It is mostly same as KNAME.
251 Some files have special formats and information sources:
254 id=_BPF-PROG.ID_ type=_BPF-PROG.TYPE_
257 tfds=_EVENTPOLL.TFDS_
263 inodes=_INOTIFY.INODES_
269 protocol=_NETLINK.PROTOCOL_[ lport=_NETLINK.LPORT_[ group=_NETLINK.GROUPS_]]
272 type=_SOCK.TYPE_[ protocol=_PACKET.PROTOCOL_][ iface=_PACKET.IFACE_]
275 pid=_TARGET-PID_ comm=_TARGET-COMMAND_ nspid=_TARGET-NSPIDS_
277 *lsfd* extracts _TARGET-PID_ and _TARGET-NSPIDS_ from
278 ``/proc/``_pid_``/fdinfo/``_fd_.
281 state=_SOCK.STATE_[ id=_PING.ID_][ laddr=_INET.LADDR_ [ raddr=_INET.RADDR_]]
284 state=_SOCK.STATE_[ id=_PING.ID_][ laddr=_INET6.LADDR_ [ raddr=_INET6.RADDR_]]
287 state=_SOCK.STATE_[ protocol=_RAW.PROTOCOL_ [ laddr=_INET.LADDR_ [ raddr=_INET.RADDR_]]]
290 state=_SOCK.STATE_[ protocol=_RAW.PROTOCOL_ [ laddr=_INET6.LADDR_ [ raddr=_INET6.RADDR_]]]
297 state=_SOCK.STATE_[ laddr=_TCP.LADDR_ [ raddr=_TCP.RADDR_]]
300 clockid=_TIMERFD.CLOCKID_[ remaining=_TIMERFD.REMAINING_ [ interval=_TIMERFD.INTERVAL_]]
304 state=_SOCK.STATE_[ laddr=_UDP.LADDR_ [ raddr=_UDP.RADDR_]]
306 *lsfd* hides ``raddr=`` if _UDP.RADDR_ is ``0.0.0.0`` and _UDP.RPORT_ is 0.
310 state=_SOCK.STATE_[ laddr=_UDPLITE.LADDR_ [ raddr=_UDPLITE.RADDR_]]
313 state=_SOCK.STATE_[ path=_UNIX.PATH_]
316 state=_SOCK.STATE_[ path=_UNIX.PATH_] type=_SOCK.TYPE_
319 Note that `(deleted)` markers are removed from this column.
320 Refer to _KNAME_, _DELETED_, or _XMODE_ to know the
321 readability of the file from the file system.
324 NETLINK.GROUPS <``number``>::
325 Netlink multicast groups.
327 NETLINK.LPORT <``number``>::
328 Netlink local port id.
330 NETLINK.PROTOCOL <``string``>::
336 NS.NAME <``string``>::
337 Name (_NS.TYPE_:[_INODE_]) of the namespace specified with the file.
339 NS.TYPE <``string``>::
340 Type of the namespace specified with the file.
341 The type is `mnt`, `cgroup`, `uts`, `ipc`, `user`, `pid`, `net`,
342 `time`, or `unknown`.
347 PACKET.IFACE <``string``>::
348 Interface name associated with the packet socket.
350 PACKET.PROTOCOL <``string``>::
351 L3 protocol associated with the packet socket.
353 PARTITION <``string``>::
354 Block device name resolved by `/proc/partition`.
357 PID of the process opening the file.
359 PIDFD.COMM <``string``>::
360 Command of the process targeted by the pidfd.
362 PIDFD.NSPID <``string``>::
363 Value of NSpid field in ``/proc/``_pid_``/fdinfo/``_fd_ of the pidfd.
365 Quoted from kernel/fork.c of Linux source tree:
368 If pid namespaces are supported then this function will also print
369 the pid of a given pidfd refers to for all descendant pid namespaces
370 starting from the current pid namespace of the instance, i.e. the
371 Pid field and the first entry in the NSpid field will be identical.
373 Note that this differs from the Pid and NSpid fields in
374 /proc/<pid>/status where Pid and NSpid are always shown relative to
375 the pid namespace of the procfs instance.
378 PIDFD.PID <``number``>::
379 PID of the process targeted by the pidfd.
382 ICMP echo request id used on the PING socket.
387 RAW.PROTOCOL <``number``>::
388 Protocol number of the raw socket.
391 Device ID (if special file).
393 SIGNALFD.MASK <``string``>::
399 SOCK.LISTENING <``boolean``>::
402 SOCK.NETS <``number``>::
403 Inode identifying network namespace where the socket belongs to.
405 SOCK.PROTONAME <``string``>::
408 SOCK.STATE <``string``>::
411 SOCK.TYPE <``string``>::
412 Type of socket. Here type means the second parameter of
423 SOURCE <``string``>::
424 File system, partition, or device containing the file.
426 STTYPE <``string``>::
427 Raw file types returned from *stat*(2): BLK, CHR, DIR, FIFO, LINK, REG, SOCK, or UNKN.
429 TCP.LADDR <``string``>::
430 Local L3 (INET.LADDR or INET6.LADDR) address and local TCP port.
432 TCP.LPORT <``number``>::
435 TCP.RADDR <``string``>::
436 Remote L3 (INET.RADDR or INET6.RADDR) address and remote TCP port.
438 TCP.RPORT <``number``>::
442 Thread ID of the process opening the file.
444 TIMERFD.CLOCKID <``string``>::
447 TIMERFD.INTERVAL <``number``>::
450 TIMERFD.REMAINING <``number``>::
453 TUN.IFACE <``string``>::
454 Network intrface behind the tun device.
457 Cooked version of STTYPE. It is same as STTYPE with exceptions.
458 For SOCK, print the value for SOCK.PROTONAME.
459 For UNKN, print the value for AINODECLASS if SOURCE is anon_inodefs.
461 UDP.LADDR <``string``>::
462 Local IP address and local UDP port.
464 UDP.LPORT <``number``>::
467 UDP.RADDR <``string``>::
468 Remote IP address and remote UDP port.
470 UDP.RPORT <``number``>::
473 UDPLITE.LADDR <``string``>::
474 Local IP address and local UDPLite port.
476 UDPLITE.LPORT <``number``>::
479 UDPLITE.RADDR <``string``>::
480 Remote IP address and remote UDPLite port.
482 UDPLITE.RPORT <``number``>::
488 UNIX.PATH <``string``>::
489 Filesystem pathname for UNIX domain socket.
495 Extended version of _MODE_. This column may grow; new letters may be
496 appended to _XMODE_ when *lsfd* supports a new state of file descriptors
497 and/or memory mappings.
500 opened of mapped for reading. This is also in _MODE_.
503 opened of mapped for writing. This is also in _MODE_.
506 mapped for executing the code. This is also in _MODE_.
509 deleted from the file system. See also _DELETED._.
512 locked or leased. _l_ represents a read, a shared lock or a read lease.
513 _L_ represents a write or an exclusive lock or a write lease. If both
514 read/shared and write/exclusive locks or leases are taken by a file
515 descriptor, _L_ is used as the flag.
518 Multiplexed. If the file descriptor is targeted by a eventpoll file,
519 this bit flag is set.
523 *lsfd* evaluates the expression passed to *--filter* option every time
524 before printing a file line. *lsfd* prints the line only if the result
525 of evaluation is `true`.
527 An expression consists of column names, literals and, operators like:
528 `DELETED`, `(PID == 1)`, `(NAME == "/etc/passwd")`, `(PID == 1) && DELETED`.
529 `DELETED`, `PID`, and `NAME` are column names in the example.
530 `1` and "/etc/passwd" are literals.
531 `==` and `&&` are operators.
533 Before evaluation, *lsfd* substitutes column names in the given
534 expression with actual column values in the line. There are three
535 different data types: `boolean`, `string`, and `number`. For columns
536 with a `boolean` type, the value can be stand-alone. For `string` and
537 `number` values, the value must be an operand of an operator, for
538 example, `(PID == 1)`. See *OUTPUT COLUMNS* about the types of
541 Literal is for representing a value directly. See BOOLLIT, STRLIT, and
542 NUMLIT. Different data types have different literal syntax.
544 An operator works with one or two operand(s). An operator has an
545 expectation about the data type(s) of its operands. Giving an
546 unexpected data type to an operator causes a syntax error.
548 Operators taking two operands are `and`, `or`, `eq`, `ne`, `le`, `lt`, `ge`, `gt`, `=~`, `!~`.
549 Alphabetically named operators have C-language
550 flavored aliases: `&&`, `||`, `==`, `!=`, `<`, `<=`, `>=`, and `>`.
552 `!` is the only operator that takes one operand.
554 `eq`, `ne`, and their aliases expect operands have the same data type.
555 Applying these operators return a `boolean`.
557 `and`, `or`, `not` and their aliases expect operands have `boolean` data
558 type. Applying these operators return a `boolean`.
560 `lt`, `le`, `gt`, `ge`, and their aliases expect operands have
561 `number` data types. Applying these operators return a `boolean`.
563 `=~` is for regular expression matching; if a string at the right side
564 matches a regular expression at the left side, the result is true.
565 The right side operand must be a string literal. See STRLIT about the
568 `!~` is a short-hand version of `not (STR =~ PAT)`; it inverts the
573 The current implementation does not define precedences within
574 operators. Use `(` and `)` explicitly for grouping the
575 sub-expressions if your expression uses more than two operators.
577 About `number` typed values, the filter engine supports only
578 non-negative integers, and non-negative floating point numbers.
580 === Semi-formal syntax
582 //TRANSLATORS: In the following messages, translate only the <``variables``>.
585 BOOLEXP0 :: COLUMN <``boolean``> | BOOLLIT | _(_ BOOLEXP _)_
587 BOOLEXP :: BOOLEXP0 | BOOLOP1 | BOOLOP2 | BOOLOP2BL | BOOLOP2CMP | BOOLOP2REG
589 COLUMN :: [\_A-Za-z][-_:A-Za-z0-9]*
591 BOOLOP1 :: _!_ BOOLEXP0 | _not_ BOOLEXP0
593 STREXP :: COLUMN <``string``> | STRLIT
595 NUMEXP :: COLUMN <``number``> | NUMLIT
597 BOOLLIT :: _true_ | _false_
599 CHARS :: ( [^\] | _\\_ | _\'_ | _\"_ )*
601 STRLIT :: _'_ CHARS _'_ | _"_ CHARS _"_
603 NUMLIT :: INTLIT | FNUMLIT
605 INTLIT :: [1-9][0-9]* | _0_
607 FNUMLIT :: INTLIT _._ [0-9][0-9]*
609 BOOLOP2 :: STREXP OP2 STREXP | NUMEXP OP2 NUMEXP | BOOLEXP0 OP2 BOOLEXP0
611 OP2 :: _==_ | _eq_ | _!=_ | _ne_
613 BOOLOP2BL :: BOOLEXP0 OP2BL BOOLEXP0
615 OP2BL :: _&&_ | _and_ | _||_ | _or_
617 BOOLOP2CMP :: NUMEXP OP2CMP NUMEXP
619 OP2CMP :: _<_ | _lt_ | _\<=_ | _le_ | _>_ | _gt_ | _>=_ | _ge_
621 BOOLOP2REG :: STREXP OP2REG STRLIT
623 OP2REG :: _=~_ | _!~_
627 *lsfd* has few options for filtering. In most of cases, what you should
628 know is *-Q* (or *--filter*) option. Combined with *-o* (or
629 *--output*) option, you can customize the output as you want.
631 //TRANSLATORS: In the following messages, don't forget to add whitespace at the end!
632 List files associated with PID 1 and PID 2 processes: ::
634 # lsfd -Q '(PID == 1) or (PID == 2)'
637 Do the same in an alternative way: ::
639 # lsfd -Q '(PID == 1) || (PID == 2)'
642 Do the same in a more efficient way: ::
647 Whitescapes can be used instead of a comma: ::
652 Utilize *pidof*(1) for list the files associated with "firefox": ::
654 # lsfd --pid "$(pidof firefox)"
657 List the 1st file descriptor opened by PID 1 process: ::
659 # lsfd -Q '(PID == 1) and (FD == 1)'
662 Do the same in an alternative way: ::
664 # lsfd -Q '(PID == 1) && (FD == 1)'
667 List all running executables: ::
669 # lsfd -Q 'ASSOC == "exe"'
672 Do the same in an alternative way: ::
674 # lsfd -Q 'ASSOC eq "exe"'
677 Do the same but print only file names: ::
679 # lsfd -o NAME -Q 'ASSOC eq "exe"' | sort -u
682 List deleted files associated to processes: ::
687 List non-regular files: ::
689 # lsfd -Q 'TYPE != "REG"'
692 List block devices: ::
694 # lsfd -Q 'DEVTYPE == "blk"'
697 Do the same with TYPE column: ::
699 # lsfd -Q 'TYPE == "BLK"'
702 List files including "dconf" directory in their names: ::
704 # lsfd -Q 'NAME =~ ".\*/dconf/.*"'
707 List files opened in a QEMU virtual machine: ::
709 # lsfd -Q '(COMMAND =~ ".\*qemu.*") and (FD >= 0)'
712 Hide files associated to kernel threads: ::
717 List timerfd files expired within 0.5 seconds: ::
719 # lsfd -Q '(TIMERFD.remaining < 0.5) and (TIMERFD.remaining > 0.0)'
724 Report the numbers of netlink socket descriptors and unix socket descriptors: ::
726 # lsfd --summary=only \
727 -C 'netlink sockets':'(NAME =~ "NETLINK:.*")' \
728 -C 'unix sockets':'(NAME =~ "UNIX:.*")'
734 Do the same but print in JSON format: ::
736 # lsfd --summary=only --json \
737 -C 'netlink sockets':'(NAME =~ "NETLINK:.*")' \
738 -C 'unix sockets':'(NAME =~ "UNIX:.*")'
743 "counter": "netlink sockets"
746 "counter": "unix sockets"
755 The *lsfd* command is part of the util-linux package since v2.38.
759 mailto:yamato@redhat.com[Masatake YAMATO],
760 mailto:kzak@redhat.com[Karel Zak]
771 include::man-common/bugreports.adoc[]
773 include::man-common/footer.adoc[]
776 include::man-common/translation.adoc[]