3

Command

grep -rHinF --colour=always -e "aa:aa:aa:aa" /

Output

grep: /dev/geom.ctl: Operation not supported by device
grep: /dev/devctl: Device busy

It seems that grep can not proceed because it is waiting for a device. How can I skip such devices?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
TaXXoR
  • 235
  • 1
  • 3
  • 12
  • Does your `grep` support `--exclude-dir` option? `grep -rHinF --colour=always --exclude-dir=/dev/ -e "aa:aa:aa:aa" /` – manatwork Oct 07 '13 at 09:48
  • @manatwork unfortunately no, the distribution I use is _pfSense_ and is based on _nanobsd_ – TaXXoR Oct 07 '13 at 09:50
  • GNU grep? `-D skip` – ninjalj Oct 07 '13 at 10:23
  • 1
    Are you *sure* you want to grep the *entire* file system? You'll likely want to skip `/proc` and probably some other trees. Actually, you likely need just a couple of top-level directories (e.g. `/etc` and similar). – peterph Oct 07 '13 at 10:26
  • @peterph I have not thought of leaving unnecessary directories out. That is a good suggestion! – TaXXoR Oct 07 '13 at 12:05

1 Answers1

6

If find is available, try:

find / -type f -exec grep -rHinF --colour=always -e "aa:aa:aa:aa" {} +

This only applies to regular files so it will skip block and character devices. See man find.

You probably want to skip directories like /proc or /sys; as Stephane Chazelas points out in the comments, some files in there will block (remain open, hanging the search) when you read them. To do this, you could try the -xdev aka. -mount directive, presuming the rest of your filesystem is on one device. If the -fstype directive works for you, that would be better (unfortunately it does not work for me on linux).

IMO, rather than fiddling with this, you should just repeat the process for whichever toplevel directories you really want to search, rather than trying to do it all in one go (in which case you may not need find...)

goldilocks
  • 86,451
  • 30
  • 200
  • 258