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?
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?
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 the find 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 by bash itself.