1

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?

muru
  • 69,900
  • 13
  • 192
  • 292
leeand00
  • 4,443
  • 10
  • 51
  • 78
  • 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 – steeldriver Dec 28 '22 at 00:55
  • @steeldriver I already tried looking for a file named that – leeand00 Dec 28 '22 at 01:17
  • Or use `.` instead of `*`? – muru Dec 28 '22 at 03:38
  • There are two possible issues: 1) The backslash is not taken as a directory path delimiter; use just `.viminfo` (the exclusion pattern is only ever tested against the filenames themselves, not against the full pathname). 2) The error is likely due to a file with a name starting with a dash. This name is likely in the current directory and will be substituted on the command line by the expansion of the `*` glob. Use `-- *` as steeldriver suggests. This has nothing to do with the `.viminfo` file. This is not an answer, as I don't know what your filenames are in the current directory. – Kusalananda Dec 28 '22 at 11:45
  • @Kusalananda ah good catch - I hadn't even considered they were trying to use backslash as a separator (I assumed it was a mistaken belief that the period needed to be escaped) – steeldriver Dec 28 '22 at 15:34
  • @steeldriver `-- *` worked. What does that do again? – leeand00 Dec 28 '22 at 16:23
  • 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?](https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean) – steeldriver Dec 28 '22 at 16:50
  • 1
    ... although [as @muru pointed out](https://unix.stackexchange.com/questions/729788/wsl2-ubuntu-wont-let-me-grep-recursively?noredirect=1#comment1383943_729788) you might want to use `.` instead of `*` (unless your intent is to skip hidden files/directories in the current directory?) – steeldriver Dec 28 '22 at 17:56

0 Answers0