The fuser command is useful to determine which files are using system resources. One of the more common uses of this command is to determine which user is active in a filesystem, which prevents the system administrator from unmounting the filesystem:
[root@localhost ~]# umount /boot umount: /boot: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
[root@localhost ~]# fuser -v /boot USER PID ACCESS COMMAND /boot: root kernel mount /boot student 29306 ..c.. bash
fuser output will include following symbols:
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.
The following table describes common options for the fuser command:
Option | Description |
---|---|
-k or –kill | Kill the process that is using the filesystem or resource. |
-i or –interactive | Prompt before killing the process (you must also use the -k option). |
-v or –verbose | Verbose; produce additional useful information. |
If you encounter the below error while running the command fuser:
fuser: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install psmisc |
Ubuntu | apt-get install psmisc |
Alpine | apk add psmisc |
Arch Linux | pacman -S psmisc |
Kali Linux | apt-get install psmisc |
CentOS | yum install psmisc |
Fedora | dnf install psmisc |
Raspbian | apt-get install psmisc |
fuser Command Examples
1. Find which processes are accessing a file or directory:
# fuser path/to/file_or_directory
2. Show more fields (`USER`, `PID`, `ACCESS` and `COMMAND`):
# fuser --verbose path/to/file_or_directory
3. Identify processes using a TCP socket:
# fuser --namespace tcp port
4. Kill all processes accessing a file or directory (sends the `SIGKILL` signal):
# fuser --kill path/to/file_or_directory
5. Find which processes are accessing the filesystem containing a specific file or directory:
# fuser --mount path/to/file_or_directory
6. Kill all processes with a TCP connection on a specific port:
# fuser --kill port/tcp