How to Find Out Who is Using a File in Linux

Configurare noua (How To)

Situatie

In this article, we will explain how to find out who is using a particular file in Linux. This will help you know the system user or process that is using an open file.

Solutie

We can use the lsof command to know if someone is using a file, and if they are, who. It reads kernel memory in its search for open files and helps you list all open files. In this case, an open file may be a regular file, a directory, a block special file, a character special file, a stream, a network file and many others – because in Linux everything is a file. Lsof is used on a file system to identify who is using any files on that file system. You can run lsof command on Linux filesystem and the output identifies the owner and process information for processes using the file as shown in the following output.

To list user specific opened files, run the following command replace tecmint with the actual user name.

Another important use of lsof is to find out the process listening on a specific port. For example identify the process listening on port 80 using the following command.

Since lsof reads kernel memory in its search for open files, rapid changes in kernel memory may result into unpredictable outputs. This is one of the major downsides of using lsof command.

For more information, look at the lsof man page:

Tip solutie

Permanent

Voteaza

(2 din 11 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?