Empty curly braces and semicolon in bash
Both {}
and ;
have special meanings in bash
but in the context of find
, it is find
which actually interprets these two (actually we want find
to interpret these two).
First of all, -exec
is an action of find
. {}
and ;
are special parameters for the -exec
predicate of find
.
The syntax for the -exec
action is:
-exec command ;
or
-exec command {} +
So we need to keep {}
and ;
from being interpreted by shell beforehand.
In the context of find .... -exec
:
{}
indicates (contains) the result(s) from thefind
expression i.e.find . -name "FILE-TO-FIND"
in this case. Note that empty curly braces{}
have no special meaning to shell so we can get away without escaping{}
As
bash
treats;
as end of a command, we need to escape this with\
i.e.\;
so that it can be parsed by-exec
not bybash
itself.
Related videos on Youtube
spiderface
Updated on September 18, 2022Comments
-
spiderface almost 2 years
What does
{} \;
string mean in bash?
I've seen it a couple of times, for example, to find and delete all files by name one must execute
find . -name "FILE-TO-FIND" -exec rm -rf {} \;
What does this string do?
-
spiderface over 8 yearsSo what does
;
do when interpreted byfind
? -
heemayl over 8 years@spiderface check my edits