Thursday, 16 June 2016

lsof cand fuser command reference

lsof is a useful tool that allows you to view files that currently have a handle on them by a process (i.e. open) - below is a few common commands that will help when debugging.

View files open by a specific user

lsof -u limited

View processes that are listening on a tcp port:

sudo lsof -i TCP:80

View handles on a specific file:

sudo lsof /var/www/html/vhost/

View open files for a specific process id:

sudo lsof -p 5123

Where similarly fuser allows you to view the processes that have handles on them - but more specifically it allows you to view open processes on a mount point:

fuser -m /mount/remote-smb-share

and also automatically kill any processes that have a handle open e.g.:

fuser -k -m /mount/remote-smb-share/file.locked


Post a Comment