How to Use the fuser Command on Linux

Using a method to quickly check the owners of running processes and applications can make process management easier. Fortunately, you’ll learn how to use the fuser command on Linux here!

The versatility of the Command Terminal makes Linux distributions stand out from their competitors. The ability to execute any task just by writing some lines in a window makes Linux the perfect choice for those working in the field of Information Technology.

One of the noticeable features is that the Terminal can aid in retrieving specific system information. For example, finding information about the process owner is possible with the help of the $fuser command.

This guide will help you learn how to use the fuser command on Linux. We’ll go over the command’s basics, its functionality, and some examples to help you make the most of it.

Understanding the $fuser Command

As mentioned before, the $fuser (short for find user) command is responsible for retrieving information about the user that’s running a process or application on a system. It achieves this by looking at the socket, directory, or file that is linked to the process.

The command can also be used to find information about the access priority of the process. It can also terminate the given process at hand.

The $fuser takes these names and directories as input and outputs the corresponding Process IDs (PIDs) associated with the input arguments.

Syntax of the $fuser Command

The $fuser command can be written with several flags and options.

We’ll be going over the common methods of calling $fuser in the Terminal.

Note: For this guide, we’ll be using Ubuntu 22.04 LTS as our Linux distribution. However, the instructions in this guide are still relevant if you’re on a previous version of Ubuntu or a different Linux distribution altogether.

The general syntax of the $fuser command is as follows:

$ fuser <option>

The aforementioned command will perform specific actions corresponding to the given option without taking any file, directory, or socket as an input argument.

To use $fuser with a given path, use the following syntax:

$ fuser <file/socket/directory>

Your input argument for the path must be one of the three specified types i.e., file, directory, or socket.

To use the $fuser command with both options and target path, use the following syntax:

$ fuser <options> <file/socket/directory>

Now that you’ve learned about the general syntax of $fuser, let’s proceed to learn about the associated options.

Options for the $Fuser Command

While $fuser can give an output if you specify the paths only, you can get more specific results using the right options.

Here are some of the most commonly used options for $fuser:

  • -: Resets previously used options.
  • -M, --ismountpoint: Kills specified processes provided they correspond to a mount point.
  • -6, --ipv6: Look for processes associated with sockets using IPv6 only.
  • -4, --ipv4: Look for processes associated with sockets using IPv4 only.
  • -u, --user: Gives the name of the process owner with the PIDs
  • -a, --all: Display files specified in the path that was accessed by a process.
  • -l, --list-signals: Displays the list of signals that are accessible by $fuser.
  • -k, --kill: Terminaltes a process.
  • -[SIGNAL]: Terminates processes using a specified signal in place of SIGKILL.
  • -i, --interactive: Prompts the user to confirm process termination.
  • -m, --mount: Locate the specified file belonging to a list and display all processes that are calling files within the filesystem.
  • -n, --namespace: Use a new namespace rather than the default one.
  • -v, --verbose: Display all information corresponding to a process, including userm access level, PIDs, etc.
  • -w: Terminate processes that only have write privileges.
  • -s, --silent: Ignore execution of -u,-v options

With these options, you’ll be able to view necessary details while being able to terminate groups of processes with a single command.

Using the $fuser Command

Now that we’ve covered the basics of the $fuser command, let’s take a look at some examples of how to use it in different cases:

Example 1: Displaying Processes Linked to a Given Directory

The $fuser command displays information about processes linked to a specific file or directory.

Aside from the PID, you can also display other relevant information using specific options.

To locate the processes linked to a directory, follow these steps:

  1. Firstly, open the Command Terminal by hitting Ctrl + Alt +T on the keyboard.
  2. Once the Terminal is open, proceed to type the following:
$ fuser <directory>

To display the processes associated with the current directory, use the following command:

$ fuser .

This will display the PIDs as output, as shown in the image below:

How to Use the fuser Command on Linux 1

In case you wish to see a more detailed output, use the following command

$ fuser -v <directory>

For example, 

$ fuser -v .
How to Use the fuser Command on Linux

  Note: To display processes that require root access, you’ll need to put sudo at the start of the command.

Example 2: Killing Processes

The $fuser command can be used to terminate a group of processes that are associated with a path. 

This can be done using the -k or --kill option. This example will show how you can use $fuser to kill a specific process. 

Follow these steps to kill a process using $fuser:

  1. Begin by opening the Command Terminal.
  2. When the terminal is open, type the following command to display information associated with the process you want to terminate:
$ sudo fuser -v <directory>
  1. Go over the displayed information to ensure you’re not terminating any important process.
  2. Once that’s done, type the following command to kill the process:
$ sudo fuser -v -k <directory>
  1. If there are some processes you’d want to keep running, type the following command:
$ sudo fuser -ki <directory>

The Terminal will now prompt you with the option to terminate the process for all PIDs associated with the directory.

Aside from killing the processes using $fuser, you can also try and use the $kill command. Unlike $fuser, which requires a path, the $kill command can directly terminate a process via its name or PID. Check out how to kill a process in Linux to learn more about the command and its features.

This concludes our guide on how to use the fuser command on Linux. We covered the basics of the command, its syntax, and options, along with ways to use it. If you have any questions or suggestions, let us know in the comments.

If this guide helped you, please share it.

Leave a Reply
Related Posts