# Text file busy (ETXTBSY) when replacing or running a binary

**Code:** `Text file busy` · **Category:** Linux · **Seen on:** Linux

You tried to overwrite an executable that is currently running, or run one that is still open for writing.

## Meaning

Linux won’t let a running program’s file be modified in place. Deploy scripts that cp over a running binary, or scripts executed right after being written (still open), hit ETXTBSY.

## Common causes

- Overwriting a running binary with cp
- Executing a file another process still has open for writing
- Copying a script and running it immediately in parallel

## Quick fix

1. Write to a temp file and mv it into place (atomic rename)
2. Stop the process before replacing
3. Wait for the writer to close the file

## Detailed fix by platform

### Linux

1. 

```bash
cp app.new /usr/local/bin/app.tmp && mv /usr/local/bin/app.tmp /usr/local/bin/app
sudo systemctl restart app
```


## How to diagnose

1. **Users** — fuser -v /usr/local/bin/app
2. **Deploy** — cp or mv?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/linux/text-file-busy)
