Linux Commands

How to use fuser command in Linux

Files or directories in Linux are being accessed by processes of a unique identity. If we want to perform any action on the specific process that is accessing a specific file or directory, we must know about the process id of that particular process. In this write-up, we are going to explain the utilization of the fuser command in Linux with the help of some examples.

What is the fuser command in Linux

There are different commands used in Linux to manage the networking and monitoring the processes, among them one very useful command is the fuser command, which is used to find out the processes being used by the file, directories, or sockets which are mentioned in the command executed. We can find out the details of the fuser command either by accessing its manual or running the “fuser” command in the terminal. To open the manual of fuser, run the command:

$ man fuser

Or using the fuser command:

$ fuser

In the above output, we can see that it generates the comments of “No process specification given” because we have not input the details of any process and explained the usage of the fuser command. To display the process details accessing the current working directory:

$ fuser -v .

In the above command, “.” is used to find out the process details of the present directory, it has displayed the “USER” name, PID of the process, ACCESS (c stand for the current directory), and COMMAND means which is using the process. We can also display the processes used to open and run the text file, for example, we have a text file with the name, mytestfile1.txt:

$ fuser -v -m mytestfile1.txt

In the above command, the “-m” flag (m signifies mount) is used to find out the processes of the filesystem which are accessing the file, mytestfile.txt. This flag is very useful to find out the processes accessing any particular file so we can kill it. We can kill the process using the fuser command, for example, we want to kill all the processes, we use the “-k” flag, and for all processes, use “.”:

$ fuser -k .

It will kill all the processes of the home directory including the process which is running the operating system and the operating system will be shut down so be cautious, and if you want that the system will ask you for killing every process or not, use the “-i” flag with “-k”:

$ fuser -ki .

In the above output, first, it will display all the processes which are being used by the home directory then it asks the user to delete or not every process. Also, there are many other signals which can be used with the fuser command. To list down all the signals, use the command:

$ fuser -l


Every file or command in Linux uses some processes of the system. If we want to know which processes are using which files, sockets, and commands we use the fuser command. We can also kill the processes by identifying the process with the fuser command and the “-k” flag is used to kill the process. In this writeup, we have discussed the use of the fuser command in detail and also explain different flags which can be used with the fuser command.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.