Linux Command - fuser
The Linux fuser command shows the PIDs of all processes that are acessing a specific file or file system. It will display a list of pids and the type of access they have.
NOTE:
- Run as root to see everything.
- Access by the kernel is only shown with the -v option.
Basic usage:
fuser /home/user1 # show all procs acessing this file
fuser -m /home/user1 # show all procs acessing any file on same FS as this file
fuser -u /home/user1 # include user id
fuser -v /home/user1 # verbose, columns with info
Killing processes:
fuser -k /data1 # kill all procs acessing this file
fuser -ki /data1 # same but interactive
fuser -kM /data1 # same but only if it is a mountpoint ( for safety )
fuser -kMi /data1 # more safe ( mountpoint only and interactive )
fuser -kw /data1 # only kill procs with write access
fuser -km /data1 # kill all processes acessing FS that this file is on
fuser -kmM /data1 # same but only if mountpoint
List signal names:
fuser -l
Showing TCP / UDP network ports:
sudo fuser -n tcp http/tcp # TCP port 80
sudo fuser -n tcp 80 # TCP port 80
sudo fuser -k -n tcp 80 # TCP port 80 - kill procs on this port
sudo fuser -u -n tcp 80 # TCP port 80 with users
sudo fuser -v -n tcp 80 # TCP port 80 verbose
sudo fuser -n udp 53 # UDP port 53
Type of access:
| c | current directory. |
| e | executable being run. |
| f | open file. f is omitted in default display mode. |
| F | open file for writing. F is omitted in default display mode. |
| r | root directory. |
| m | mmap’ed file or shared library. |
| . | Placeholder, omitted in default display mode. |
Parameters:
| -a | show all files even if not accessed |
| -c | same as -m |
| -f | does nothing |
| -k | kill ( SIGKILL ) |
| -i | interactve, ask before kill |
| -I | use inodes instead of names |
| -l | list signal names |
| -m name | list procs for all files on same FS as this file |
| -M | only run request if mountpoint has been specified ( for safety ) |
| -w | only kill processes with write access |
| -n | namespace (file, udp, tcp ) |
| -s | silent ( -u and -v ignored, don’t use with -a ) |
| -SIGNAL | alternate signal instead of SIGKILL ex: -HUP or -1 |
| -u | show username |
| -v | verbose |
| -V | version |
| -4 | only IPv4 |
| -6 | only IPv6 |