Contents

How To Use the Linux Fuser Command

06 Mar 2018 3 149  0
How To Use the Linux Fuser Command
How To Use the Linux Fuser Command

 

The Linux fuser command is usually used to help identify what processes are using a specific file, unix socket, or file system. In this guide we plan to teach you a couple examples to demonstrate how you can use the fuser command on a Linux VPS.

SSH into the Server

In order to be able to run fuser commands, you will require SSH access to the server. Connect to your server via SSH and run fuser.

No process specification given

Usage: fuser [-fMuvw] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME...

fuser -l

fuser -V

Show which processes use the named files, sockets, or filesystems.



-a,--all              display unused files too

-i,--interactive      ask before killing (ignored without -k)

-k,--kill             kill processes accessing the named file

-l,--list-signals     list available signal names

-m,--mount            show all processes using the named filesystems or block device

-M,--ismountpoint     fulfill request only if NAME is a mount point

-n,--namespace SPACE  search in this name space (file, udp, or tcp)

-s,--silent           silent operation

-SIGNAL               send this signal instead of SIGKILL

-u,--user             display user IDs

-v,--verbose          verbose output

-w,--writeonly        kill only processes with write access

-V,--version          display version information

-4,--ipv4             search IPv4 sockets only

-6,--ipv6             search IPv6 sockets only

-                     reset options



udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

This output should notify you that no process specification is provided, it will also give you some basic usage examples and options.

The –v or –verbose is used commonly and gives a verbose output. An example of this is to list every process which uses the current directory.

fuser -v .

In the case that your current directory is the root directory, you will receive an output similar to the one below.

# fuser -v .
USER        PID ACCESS COMMAND

...

root         37 .rc.. bash

root         64 .rc.. systemd-journal

root         65 .rc.. systemd-udevd

root        193 .rc.. rpcbind

root        197 .rc.. systemd-logind

root        199 .r... cron

messagebus  200 .rc.. dbus-daemon

syslog      211 .rc.. rsyslogd

root        296 .r... saslauthd

root        297 .r... saslauthd

root        299 .rc.. sshd

bind        304 .r... named

root        321 .r... dovecot

root        329 .r... log

root        334 .r... config

mysql       336 .r... mysqld

root        370 .rc.. agetty

root        371 .rc.. agetty

root        396 .rc.. xinetd

root        429 .r... sendmail-mta

root        449 .rc.. apache2

www-data    455 .rc.. apache2

www-data    456 .rc.. apache2

www-data    457 .rc.. apache2

www-data    458 .rc.. apache2

www-data    459 .rc.. apache2

...

In the output above you will see information such as the USER, PID, ACCESS, and the COMMAND which was used to initiate the procedure.

ACCESS reveals letters denoting the type of access; there are multiple types of these:

c - current directory

e - executable being run

r - root directory

f - open file (omitted in default display mode)

F - open file for writing (omitted in default display mode)

m - mmap’ed file or shared library

A different usage for fuser is to list every process which uses UDP and TCP sockets on your Linux VPS.

In our example, we list every process which uses the TCP port 80. You can run the command below to find this.

fuser -v -n tcp 80

In the case that you have Apache installed and running on your server, you will receive an output similar to the following.

# fuser -v -n tcp 80

USER        PID ACCESS COMMAND

80/tcp:              root        449 F.... apache2

www-data    455 F.... apache2

www-data    456 F.... apache2

www-data    457 F.... apache2

www-data    458 F.... apache2

www-data    459 F.... apache2

www-data    511 F.... apache2

www-data    512 F.... apache2

www-data    513 F.... apache2

Fuser can be used to destroy particular processes as well. For example, to kill the processes which are using the TCP port 80, you can use the command shown below.

fuser -k 80/tcp

Keep in mind that this is going to kill your Apache service if it is running currently.

You can also use fuser is to kill every process which accesses the ‘/home’ directory in any way, as shown below.

fuser -km /home

If you’re looking for more options and usage examples for fuser, you can refer to the fuser main page.

man fuser
0 Comments
Add a comment

Leave a Reply