I have begun to combine different commands in the linux terminal. I am wondering why the backslash and semicolon are required for a command such as:
find ./ -name 'blabla' -exec cp {} ./test \;
when a simple cp command is simply:
cp randomfile ./test
without the \;
Are they to clearly indicate the end of a command, or is it simply required in the documentation? What is the underlying principle?
A backslash escapes the next character from being interpreted by the shell. If the next character after the backslash is a newline character, then that newline will not be interpreted as the end of the command by the shell. Instead, it effectively allows a command to span multiple lines.
Command-Semicolon (;): Find misspelled words in the document.
In Unix systems, and even some programming languages like C, the role of the backslash is to indicate to the system that the next character has a special meaning. Therefore, it works as an escape character. For example, a lowercase n, when used with a backslash, \n, indicates a new line character.
The backslash (\) character is used to mark these special characters so that they are not interpreted by the shell, but passed on to the command being run (for example, echo ). So to output the string: (Assuming that the value of $X is 5): A quote is ", backslash is \, backtick is `.
The backslash before the semicolon is used, because ;
is one of list operators (or &&
, ||
) for separating shell commands. In example:
command1; command2
The find
utility is using ;
or +
to terminate the shell commands invoked by -exec
.
So to avoid special shell characters from interpretation, they need to be escaped with a backslash to remove any special meaning for the next character read and for line continuation.
Therefore the following example syntax is allowed for find
command:
find . -exec echo {} \; find . -exec echo {} ';' find . -exec echo {} ";" find . -exec echo {} \+ find . -exec echo {} +
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With