how to use linux fuser command

How To Use the Linux Fuser Command

Spread the love

We’ll show you, How To Use the Linux Fuser Command. The fuser command is used to identify which processes are using a specific file, unix socket or file system. In this tutorial we are going to show you few examples on how to use the fuser command on a Linux VPS.

To be able to use fuser command you need to have SSH access to the server. Connect to your server via SSH and run fuser.

# 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]]]

The output will notify you that no process specification is given and will show you some basic usage examples and options.

The -v or --verbose provides verbose output and it is commonly used. One example is to list all the processes that are using the current directory.

fuser -v .

If your current directory is the root directory, the output should be similar to this one:

# 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

The above output shows information like the USER, PID, ACCESS and the COMMAND used to start the process. ACCESS shows letters denoting the type of access and there are several:

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

Another common usage of fuser is to list the processes using the UDP and TCP sockets on your Linux VPS. For example to list the processes using the TCP port 80 you can use the following command:

fuser -v -n tcp 80

If you have Apache installed and running on your server, the output should be similar to the following one:

# 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 kill specific processes too. For example, to kill the processes which are using TCP port 80, you can use the following command:

fuser -k 80/tcp

Please note, this will kill your Apache service if it is running at the moment.

Another example is to kill all processes accessing the /home directory in any way:

fuser -km /home

For more options and usage examples you can refer to the fuser man page.

man fuser

If you are one of our Linux Server Support services, you can always talk with one of our Linux Experts about Linux Fuser Command and how you can benefit from it.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *