What is the meaning of {} \; in find -exec sed

sed

Solution

That's not actually for `sed`, it's for `find`. That line is telling `find` to find matching files and, when it finds them, execute `sed`. The `{}` is where the filename will be on the `sed` command line, and the `\;` marks the end of the `sed` command line. (In theory you could then continue with other `find` actions; they would only happen if `sed` returned `0`.)

So if `find` finds the file `/home/foo/bar`, the `sed` command line will be

sed -i 's/ugly/beautiful/g' /home/foo/bar

Problem

Given two examples of sed. ``` sed -i 's/ugly/beautiful/g' /home/bruno/old-friends/sue.txt ``` This is easy for me to understand. But this: ``` $ find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \; ``` Why is `{} \;` important in the second one? What the significance and meaning of this? I assume `;' is for -exec. But why should it be escaped and what does the braces mean? Can they be imagined to be similar to C function's scope?

Original source