Skip to main content

ggrep --devices=skip

Every now and then I'd like to (recursively) search for patterns in a directory tree. Since Solaris' grep(1) does not understand -r, I used SUNWggrep. But grep'ing through e.g. /etc never seems to come to an end, and truss(1) knows why:

$ /usr/sfw/bin/ggrep --version | head -1
grep (GNU grep) 2.5
$ truss -elfda /usr/sfw/bin/ggrep -D skip -r foo /etc
8341/1:          0.0448 open64("/etc/cron.d/FIFO", O_RDONLY)            = 3
8341/1:          0.0454 fstat64(3, 0xFFBFFA78)                          = 0
8341/1:         read(3, 0x00044000, 32768)      (sleeping...)
Well, I won't comment on the fact that we have devices in /etc at all, but I explicitly told grep to skip devices. Apparently this option is just being ignored. Using the latest GNU/grep CVS checkout does help and the changelog does indeed mention a fix for the --devices option.

Oh, of course: this could be done with find too, but GNU/grep is so much easier than:
$ find /etc -type f -exec grep foo '{}' +
Hint: add "-D skip" to your GREP_OPTIONS environment variable, that way it's passed to GNU/grep automatically.

Update: a careful reader noticed that I confused SUNWggrep and SMCgrep - I did indeed and corrected it, finally. Thanks for the hint! For the record, the current version of SMCgrep does NOT have this problem, it's all good! :-)