How to use Linux fuser command ?

Linux

The Linux fuser command is a useful tool for managing user access to files and directories. It allows you to view, identify, and control user access to files and directories on a Linux system. 

Here at Fixwebnode, we will discuss the fuser command in detail and provide several practical examples.

 

Facts about the fuser command ?

The fuser command is a Linux utility used to identify which processes are currently accessing a given file or directory. It displays the PID (process ID) of each process that has an open file descriptor for the specified file or directory. This can be used to identify processes that are using a file or directory, as well as to terminate processes that are using a file or directory.

 

fuser command Syntax

The basic syntax of the fuser command is as follows:

$ fuser [options] FILE/DIRECTORY

 

fuser command Options

The fuser command has a number of options that can be used to customize its output and behavior. The most commonly used options are as follows:

  • -v: This option is used to display verbose output of the command.
  • -k: Kill processes that are using the specified file or directory
  • -s: This option is used to search for processes that are using a particular file or directory recursively.
  • -u: This option is used to search for processes that are using a particular user's files or directories.
  • -i: This option is used to display only the process IDs of the processes that are using a particular file or directory.
  • -m: Display file access mode

 

Examples of using fuser ?

1. List all processes that are currently accessing a file

This example will list all processes that are currently accessing a file named "example.txt":

$ fuser example.txt
example.txt: 1234

This output indicates that the file is currently being accessed by a process with a PID of 1234.

 

2. List all processes that are currently accessing a directory

This example will list all processes that are currently accessing a directory named "example_dir":

$ fuser -v example_dir
example_dir: 1234 (rw)

This output indicates that the directory is currently being accessed by a process with a PID of 1234, and that the process has read and write access.

 

3. Kill all processes that are currently accessing a file

This example will kill all processes that are currently accessing a file named "example.txt":

$ fuser -k example.txt
Killed process 1234

This output indicates that the process with a PID of 1234 has been killed.

 

[Need help in fixing Linux system issues ? We can help you. ]

 


Conclusion

This article covers the Linux fuser command and provided several practical examples of its usage. In fact, you can now manage user access to files and directories, andused to identify and control user access to files and directories on a Linux system.

Your Cart