0

I use find a lot, generally using the -name or -iname parameters.

I would like it to highlight the matching part in the files it finds (like grep does).

For example: find . -iname "*FOO*" would highlight instances for FOO

I know I could pipe it into grep but I'd rather not write two commands each time.

Is there a simple way to do it?

MasterScrat
  • 7,090
  • 14
  • 48
  • 80
  • name and iname require the full name of the file though, what do you actually want to match? Show examples please. – 123 Oct 22 '15 at 14:29
  • @123 no you can use wildcards... I added an example. – MasterScrat Oct 22 '15 at 14:36
  • Yes but the wildcards match the full filename. You can also use other regex. Are you saying you only want to match literal characters? – 123 Oct 22 '15 at 14:39
  • @123 ok I see your point... yes I would only want to match literal characters. I could pipe it into `grep` but then I would need to write both every time – MasterScrat Oct 22 '15 at 14:42
  • I formulated that problem in a better way here: http://stackoverflow.com/questions/33389064/find-all-files-whose-names-contain-a-given-string-and-highlight-it – MasterScrat Oct 28 '15 at 12:32

1 Answers1

1

eg. like this:

find /home/ -type f | grep -i --color=always *.cpp
xeyez
  • 31
  • 4
  • @kenorb What exactly does not work with this solution? -i might fail on some versions of grep on some distributions. Path and reg-exp are just made up, but you can figure it out. – xeyez Oct 23 '15 at 11:02
  • For example `*.cpp` won't work as it's expanded by shell before it'll be used by `grep`. Using `"cpp$"` could help instead. – kenorb Oct 23 '15 at 11:04