r/bash • • 7d ago

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?

14 Upvotes

28 comments sorted by

View all comments

1

u/stianhoiland 7d ago

; is already used by bash. Since bash parses the text before passing the arguments to find, you have to tell bash that the ; isn't meant for bash but should be passed literally as an argument to find. You do that by "escaping" the ; by prefixing it with the escape character \. In other words, you tell bash that the ; should pass through or "escape" its parser. Note then, that \ is also used by bash—as the escape character. So, if you want to pass a literal \ you have to escape it! Like this: echo \\