Skip to content Skip to sidebar Skip to footer

how to see what has a file open

In this article, nosotros will explicate how to find out who is using a item file in Linux. This will assistance you know the system user or process that is using an open file.

We can utilise the lsof control to know if someone is using a file, and if they are, who. It reads kernel retention in its search for open files and helps you list all open up files. In this case, an open file may exist a regular file, a directory, a block special file, a character special file, a stream, a network file and many others – considering in Linux everything is a file.

Lsof is used on a file system to identify who is using whatever files on that file arrangement. You tin can run lsof control on Linux filesystem and the output identifies the possessor and process information for processes using the file every bit shown in the following output.

                  $ lsof /dev/null                

List of All Opened Files in Linux

Command    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE Name systemd   1480 tecmint    0r   CHR    1,iii      0t0    6 /dev/nothing sh        1501 tecmint    0r   CHR    one,3      0t0    6 /dev/zippo sh        1501 tecmint    1w   CHR    1,three      0t0    vi /dev/null dbus-daem 1530 tecmint    0u   CHR    1,3      0t0    6 /dev/nothing xfce4-ses 1603 tecmint    0r   CHR    one,3      0t0    six /dev/goose egg xfce4-ses 1603 tecmint    1w   CHR    1,3      0t0    half-dozen /dev/goose egg at-spi-bu 1604 tecmint    0r   CHR    1,3      0t0    half dozen /dev/null dbus-daem 1609 tecmint    0u   CHR    ane,three      0t0    6 /dev/zero at-spi2-r 1611 tecmint    0u   CHR    1,3      0t0    6 /dev/null xfconfd   1615 tecmint    0u   CHR    1,iii      0t0    6 /dev/nothing xfwm4     1624 tecmint    0r   CHR    1,three      0t0    half dozen /dev/nil xfwm4     1624 tecmint    1w   CHR    one,three      0t0    6 /dev/null xfce4-pan 1628 tecmint    0r   CHR    1,3      0t0    half-dozen /dev/zilch xfce4-pan 1628 tecmint    1w   CHR    one,3      0t0    6 /dev/zilch Thunar    1630 tecmint    0r   CHR    i,3      0t0    half dozen /dev/zippo Thunar    1630 tecmint    1w   CHR    1,3      0t0    6 /dev/null xfdesktop 1632 tecmint    0r   CHR    ane,3      0t0    6 /dev/nothing xfdesktop 1632 tecmint    1w   CHR    ane,three      0t0    six /dev/null ....                

To listing user specific opened files, run the following command replace tecmint with the bodily user proper noun.

                  $ lsof -u tecmint                

List of Files Opened past User

COMMAND    PID    USER   FD      Type             DEVICE  SIZE/OFF       NODE Name systemd   1480 tecmint  cwd       DIR                8,3      4096          ii / systemd   1480 tecmint  rtd       DIR                8,3      4096          ii / systemd   1480 tecmint  txt       REG                8,iii   1595792    3147496 /lib/systemd/systemd systemd   1480 tecmint  mem       REG                viii,three   1700792    3150525 /lib/x86_64-linux-gnu/libm-2.27.and so systemd   1480 tecmint  mem       REG                8,3    121016    3146329 /lib/x86_64-linux-gnu/libudev.so.ane.six.9 systemd   1480 tecmint  mem       REG                8,3     84032    3150503 /lib/x86_64-linux-gnu/libgpg-mistake.and then.0.22.0 systemd   1480 tecmint  mem       REG                8,3     43304    3150514 /lib/x86_64-linux-gnu/libjson-c.so.3.0.ane systemd   1480 tecmint  mem       REG                8,three     34872    2497970 /usr/lib/x86_64-linux-gnu/libargon2.and then.0 systemd   1480 tecmint  mem       REG                8,3    432640    3150484 /lib/x86_64-linux-gnu/libdevmapper.and then.1.02.1 systemd   1480 tecmint  mem       REG                eight,3     18680    3150450 /lib/x86_64-linux-gnu/libattr.so.1.1.0 systemd   1480 tecmint  mem       REG                eight,3     18712    3150465 /lib/x86_64-linux-gnu/libcap-ng.so.0.0.0 systemd   1480 tecmint  mem       REG                8,3     27112    3150489 /lib/x86_64-linux-gnu/libuuid.so.i.3.0 systemd   1480 tecmint  mem       REG                eight,three     14560    3150485 /lib/x86_64-linux-gnu/libdl-2.27.so ...                

Some other important use of lsof is to find out the procedure listening on a specific port. For example place the process listening on port 80 using the following control.

                  $ sudo lsof -i TCP:80                

Find Out Procedure Listening Port

Command  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME httpd    903   root    4u  IPv6  20222      0t0  TCP *:http (Heed) httpd   1320 apache    4u  IPv6  20222      0t0  TCP *:http (Listen) httpd   1481 apache    4u  IPv6  20222      0t0  TCP *:http (LISTEN) httpd   1482 apache    4u  IPv6  20222      0t0  TCP *:http (LISTEN) httpd   1493 apache    4u  IPv6  20222      0t0  TCP *:http (LISTEN) httpd   1763 apache    4u  IPv6  20222      0t0  TCP *:http (LISTEN) httpd   2027 apache    4u  IPv6  20222      0t0  TCP *:http (LISTEN) httpd   2029 apache    4u  IPv6  20222      0t0  TCP *:http (Mind) httpd   2044 apache    4u  IPv6  20222      0t0  TCP *:http (Listen) httpd   3199 apache    4u  IPv6  20222      0t0  TCP *:http (LISTEN) httpd   3201 apache    4u  IPv6  20222      0t0  TCP *:http (Mind)                

Note: Since lsof reads kernel memory in its search for open up 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:

$ homo lsof                

That's all! In this article, nosotros have explained how to know who is using a particular file in Linux. We accept shown how to place the owner and process information for processes using an open file. Use the feedback form beneath to reach us for whatever questions or comments.

If Yous Capeesh What We Do Hither On TecMint, You Should Consider:

TecMint is the fastest growing and about trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider ownership us a coffee ( or 2 ) equally a token of appreciation.

Support Us

We are thankful for your never ending support.

vizcarraoffs1956.blogspot.com

Source: https://www.tecmint.com/find-out-who-is-using-a-file-in-linux/

Post a Comment for "how to see what has a file open"