Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the lsof command in linux to view the process information of a file

Shulou Source: shulou.com Published: 2022-06-02 14:44:50 10月14日 Update

Xiaobian to share with you the use of linux lsof command to view the file process information, I hope you read this article after the harvest, let us discuss it together!

The lsof command is used to view files opened by processes, processes opening files, and ports opened by processes (TCP, UDP). Retrieves/restores deleted files. Lsof is a very convenient system monitoring tool, because the lsof command needs to access core memory and various files, so it needs to be executed by root user.

In linux, everything exists as a file, which provides access not only to regular data but also to network connections and hardware. So in the background, applications such as TCP and UDP sockets are assigned a file descriptor that, regardless of the nature of the file, provides a common interface for interaction between the application and the underlying operating system. Because the descriptor list of an application's open files provides a lot of information about the application itself, being able to view this list through the lsof tool is helpful for system monitoring and troubleshooting.

Syntax format: lsof [parameter] [file]

Common parameters:

-a List the processes that open files-c List the files opened by the specified process-g List the process details of the UID number-d List the processes occupying the file number +d List the files opened under the directory +D Recursively List the files opened under the directory-n List the files using NFS-i List the qualified processes-p List the files opened under the specified process number-u List the process details of the UID number-h Display help information-v Display version information

Reference Example

The simplest usage is to enter lsof directly to view the progress information of the file:

[root@linuxcool ~]# lsof

List GID Number Process Details:

[root@linuxcool ~]# lsof -g

List open files in directory:

[root@linuxcool ~]# lsof +d /root

Recursively list open files in directories:

[root@linuxcool ~]# lsof +D /home/linuxcool

List files that use NFS:

[root@linuxcool ~]# lsof -n /root After reading this article, I believe you have a certain understanding of the process information of using the lsof command to view files in Linux. If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Tags: Files processes information commands applications directories programs systems applications details parameters tools data users articles recursion help operating system not only between Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL Redmi Apple Linux