# Using find to run a command on multiple files

Find has an `-exec` action for running a command against found files.

```bash
# create backups of all markdown files
find . -type f -name '*.md' -exec cp {} {}.bak \;
```

The command will be executed for each found file. The construct '{}' will be replaced by the current file name. The command must be terminated with a semi-colon that must be escaped to protect it from interpretation by the shell.

## A word of caution

There are both security and performance implications which may be mitigated by using one of the variations `-exec command {} +`, `-execdir command` or `-execdir command {} +`.

Source: `man find`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.eliasnorrby.com/bash/find-exec.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
