May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

open files in linux

This is useful to find out which file is blocking a partition which has to be unmounted and gives a typical error of:

# umount /home/
umount: unmount of /home failed: Device busy

umount impossible because a file is locking home

Find opened files on a mount point with fuser or lsof:

# fuser -m /home # List processes accessing /home

# lsof /home/ctechz/

About an application:
# lsof -p 3324

About a single file:
# lsof /usr/local/src/firefox/firefox

FreeBSD and most Unixes

# fstat -f /home # for a mount point
# fstat -p PID # for an application with PID
# fstat -u user # for a user name

To list all the open files on the var filesystem:
# lsof +D /var

To list all open files in your current directory only:
# lsof +d .

To list all open Internet files:
# lsof -i

To list all files currently open by user joe:
# lsof -u jake

To list all files open by syslog-ng (this is a great quick way to find logs!):
# lsof -c syslog

To list all files open by pid:
# lsof -p PID

List sockets related to port 80
# lsof -i :80

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>