How and when is {} replaced by find

By David Feimer

Posted June 17, 2026 in find search

A user at https://community.unix.com asked how find passes the name of a matched file to a sub-process in order to replace the {} placeholder.

The {} placeholder is used with the -exec option to find. The -exec option takes a command, including command line arguments, and executes the command for each file or directory matched by previous tests.

For example, if you are searching all regular files to try and find where the shell’s PATH variable is set, you could execute the following:

find . -type f -exec grep -H PATH {} \;

The first part of the find command – find . -type f – searches the directory tree starting at the current working directory (the period). For each regular file found, find creates a command string.

For example, if find finds a regular file named foo.txt then the command string created by find would be:

grep -H PATH foo.txt

find then spawns a child process and executes the command string that was just built.

So, the name of the file is not passed to the child processes. The name of the file is already substituted into the command before the command is executed.