Your error is because you are using double quotes (
"), which allow the contents to be interpreted by the shell before it gets to
grep -r 'c:\\' . instead.
echo 'c:\' > test
ire@localhost$ cat test
ire@localhost$ grep -r 'c:\\' test
\ has a special meaning, both to the shell and to grep. It's used as an escape character, to allow the next character to be interpreted literally.
When you do
grep "c:\\", the shell picks up the content, converts it to the literal string
c:\, and passes that to
grep sees the single backslash, and interprets it as an escape character. But there's no character following the
\ to escape! So, quite reasonably it complains.
Using single quotes (
') protects the content from the shell. But you still need two slashes, because you need to tell
grep this is a literal backslash you are wanting to search for.
Alternatively, you could have done:
grep -rF 'C:\' .
grep -rF "C:\\" .
-F option to grep (formerly known as the
fgrep command) tells
grep to look for fixed strings, and therefore there's nothing to escape and the backslash is not special to
grep (but still is for the shell inside double quotes).