I am trying to understand this line:
find $HOME -name "*.c" -exec grep "find this string" {} /dev/null \;
I understand the majority of it, but I am not sure about the /dev/null that appears after the {} and before the ;.
find locates every C program file, and then for each file, grep looks for the line that contains the string... and then is it sending all the errors to /dev/null?
It's used to force grep to print the matching file name, only useful in greps that don't have a specific option to do so. Look:
$ cat file
1
2
3
$ grep 2 file
2
$ grep 2 file /dev/null
file:2
It used to be required to get that output but with GNU grep (and others?) these days you can do this instead:
$ grep -H 2 file
file:2
You may want to check the sell-by-date on your text book ;-).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With