Linux ETXTBSYMedium

Error 'File busy' in Linux: causes and fixes

The 'File busy' error occurs when a process locks a file. In this article, you'll learn how to find and terminate that process to free the file.

Updated at February 16, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 11+CentOS 8+All distributions with kernel 3.x+

What the ETXTBSY Error Means

The ETXTBSY error (often displayed as Text file busy or Device or resource busy) occurs in Linux when you attempt to perform an operation on a file (delete, modify, rename), but the system detects that the file is currently in use by an active process. This is a kernel protection mechanism to prevent data corruption or inconsistent states.

Typical scenarios for its appearance:

  • Attempting to delete or overwrite an executable file (.exe, binary) that is currently running.
  • A file is open in a program (text editor, IDE, antivirus) with a write lock.
  • The file is located on a network file system (NFS) and is locked by a remote process.

Symptom: commands like rm, mv, vim, or others terminate with the message Text file busy or Resource temporarily unavailable.

Causes

  1. Executable file is running
    You are trying to delete or overwrite a binary file or script that is currently being executed by the kernel as a process. Linux does not allow modifying executable files while they are running.
  2. File is open by another process with an exclusive lock
    Some applications (e.g., databases, editors) may open files in a mode that prevents other processes from reading or writing to them.
  3. Network File System (NFS) locks the file
    When using NFS, a remote client or server may hold a lock on the file, leading to a local ETXTBSY error.
  4. File is used as a shared library
    Although shared libraries (.so) can usually be overwritten, in rare cases (e.g., when actively loaded into memory) the kernel may temporarily lock them.
  5. Antivirus or monitoring system
    Daemons like clamd or auditd may scan the file and temporarily lock it for analysis.

Solutions

Method 1: Use lsof to Find and Manually Terminate the Process

lsof (list open files) is a utility that shows which processes are using a specified file.

  1. Install lsof if it's not present:
    # For Ubuntu/Debian
    sudo apt update && sudo apt install lsof
    
    # For CentOS/RHEL/Fedora
    sudo yum install lsof   # or dnf install lsof
    
  2. Find the process holding the file:
    lsof /path/to/file
    

    Example output:
    COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    vim     1234 user   txt    REG    8,1   10240 12345 /home/user/script.sh
    

    Here, PID (Process ID) is 1234.
  3. Terminate the process:
    kill 1234
    

    If the process does not respond to a regular signal, use force termination:
    kill -9 1234
    
  4. Repeat the file operation (deletion, editing, etc.).

⚠️ Important: Do not terminate system processes (e.g., systemd, sshd) without understanding the consequences. Ensure the PID belongs to the application that is actually working with your file.

Method 2: Use fuser for Quick Termination

fuser is a more aggressive utility that can immediately terminate all processes using a file.

  1. Install fuser (usually included in the psmisc package):
    sudo apt install psmisc   # Ubuntu/Debian
    sudo yum install psmisc   # CentOS/RHEL
    
  2. View processes (optional):
    fuser -v /path/to/file
    
  3. Automatically terminate processes:
    sudo fuser -k /path/to/file
    

    The -k flag sends a SIGKILL signal to all processes using the file. For a softer approach, use -TERM (default):
    sudo fuser -TERM /path/to/file
    
  4. Verify the file is released and repeat the operation.

Method 3: Working with NFS and Network File Systems

If the file is on an NFS share, local lsof/fuser commands may not see the remote process. Actions:

  1. On the client (where the error occurs) find the PID:
    fuser -k /mnt/nfs/file
    
  2. If that doesn't work, unmount and remount the NFS share:
    sudo umount /mnt/nfs
    sudo mount -t nfs server:/export /mnt/nfs
    

    Or force a remount (if supported):
    sudo mount -o remount /mnt/nfs
    
  3. On the NFS server check if any process is holding the file:
    lsof /export/file
    

    And terminate it.

Method 4: Wait for the File to Be Released

Sometimes a file is locked briefly (e.g., during log writing or caching). If the process terminates on its own:

  1. Wait a few seconds and retry the operation.
  2. Use a wait loop (for scripts):
    while lsof /path/to/file >/dev/null; do sleep 1; done
    echo "File released"
    

Method 5: System Reboot (Last Resort)

If none of the methods work and the file is critically important and cannot wait, reboot the computer. This will guaranteed release all resources.

sudo reboot

💡 Tip: After rebooting, check if the process locking the file starts automatically (via systemd, cron). Disable it if necessary.

Prevention

To avoid the ETXTBSY error in the future:

  • Close files after use — don't leave them open in editors or other programs.
  • Do not run the same executable file multiple times simultaneously if it is not designed for it (e.g., via systemd or cron).
  • Use lock files in scripts and applications to coordinate access to resources.
  • When updating binary files, stop related services first:
    sudo systemctl stop service_name
    # Replace the file
    sudo systemctl start service_name
    
  • For NFS, configure mount options with noac (no attribute caching) or actimeo=0 if locks occur frequently.

Conclusion

The ETXTBSY error is a signal that a file is temporarily unavailable due to process activity. Using utilities like lsof and fuser, you can quickly identify and remove the lock. In most cases, one of the first two methods is sufficient. Remember safety: only terminate processes that are definitely not system-critical.

F.A.Q.

Why does the 'File busy' error occur in Linux?
How to find the process that is using the file?
What to do if the process cannot be terminated?
Can the process locking the file be killed automatically?

Hints

Identify the process locking the file
Terminate the found process
Retry the file operation
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community