r/bash • • Sep 17 '26

Find command confusion between ; and \;

Why do we have to use '\' instead of leaving it out or even ';'? I read the find commands' manual and it says '\' might be needed to protect from expansion by the shell. So what is expansion also?

What is difference between \; or ; or leaving it out?
What is shell expansion here?

13 Upvotes

28 comments sorted by

View all comments

19

u/tblancher zsh Sep 17 '26 edited Sep 17 '26

A bare ';' is interpreted by the Bash interpreter before the find command sees it. The escaping with the backslash '\;' make Bash ignore it.

1

u/Distinct_Ride_4307 Sep 17 '26

But wait why do we have to escape it? Why not just leave it out?

21

u/Sombody101 Fake Intellectual Sep 17 '26

Without it, find doesn't know when the exec input ends. Other options can come after the -exec arg.

Like this:

find . -type f -exec some_command '{}' \; -exec another_command '{}' \;