Sunday 4 March 2012

How to check for 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

No comments:

Post a Comment