I can't seem to recursively search with grep for some reason in WSL2.

me@SOMEHOST:~$ grep -r -e "DATASTORE_BAKs" --exclude=SOMEHOST-2\.viminfo *
grep: SOMEHOST-2.viminfo: invalid context length argument

It seems to have something to do with my .viminfo file, but I can't exclude it properly and I can't even ignore the file using the ignore binary arg.

The file seems to contain alot of -- characters and I'm wondering if that's screwing it up.

I also did a file command on it and it doesn't warrant much:

le ./.viminfo
./.viminfo: data

How can I make this work again?

  • 2
    Do you get a different result if you do grep -r -e "DATASTORE_BAKs" --exclude=SOMEHOST-2\.viminfo -- * ? It's more likely that you have a file named something like -ASOMEHOST-2\.viminfo or -CSOMEHOST-2\.viminfo in the current directory Dec 28, 2022 at 0:55
  • @steeldriver I already tried looking for a file named that
    – leeand00
    Dec 28, 2022 at 1:17
  • Or use . instead of *?
    – muru
    Dec 28, 2022 at 3:38
  • 1
    @leeand00 it tells grep to treat everything following as a non-option (i.e. filename) argument, even if it begins with a -. See for example What does "--" (double-dash) mean? Dec 28, 2022 at 16:50
  • 1
    ... although as @muru pointed out you might want to use . instead of * (unless your intent is to skip hidden files/directories in the current directory?) Dec 28, 2022 at 17:56


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.