How to Use the fuser Command to Identify Processes Locking a File in Linux

The “Device is Busy” Error

If you have spent any time managing Linux servers, you have likely encountered the infuriating Device or resource busy error. This happens when you attempt to unmount a USB drive, delete a critical system file, or restart a service, but the Linux kernel blocks you because an unknown background application currently has that file or directory locked open.

Instead of guessing which application is holding the file hostage or violently rebooting the entire server, you can use the built-in fuser command to instantly identify the exact Process ID (PID) responsible for the lock.

Step 1: Identifying the Locking Process

The fuser command acts as an x-ray for your filesystem. To find out which program is locking a specific file (for example, a database file named production.db), open your terminal and run:

sudo fuser -v /var/lib/mysql/production.db

The -v (verbose) flag is critical here. Without it, fuser will only output a raw number. With verbose mode enabled, the command outputs a clean table detailing the USER who owns the process, the exact PID (Process ID), the type of access (such as F for open for writing), and the COMMAND (the name of the application, like mysqld).

Step 2: Checking Entire Directories or Mount Points

If you are trying to safely eject a USB drive or unmount a network share mounted at /mnt/backup, you need to see if any file inside that directory is being used. You can point fuser at the mount point:

sudo fuser -vm /mnt/backup

The -m flag tells fuser to inspect the entire mounted filesystem. It will list every single process currently interacting with any file inside that directory. If a user is currently running a backup script or simply has their terminal cd‘d into that directory, fuser will reveal them.

Step 3: Forcibly Killing the Locking Process

Once you identify the culprit, you can either gracefully shut down the application or use fuser to violently terminate it. If you add the -k (kill) flag, fuser will automatically send a SIGKILL signal to every process interacting with the file or directory.

sudo fuser -k -v /mnt/backup

Warning: Use the -k flag with extreme caution. If you run this on a critical system directory, you will instantly crash the entire server. Always run the command without -k first to verify exactly which processes you are about to destroy.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.