In Linux, you have [`strace`][1]:

 strace -f sh -c 'grep word1 word2 > file.txt'

Here we use `-f` to tell `strace` to trace child process.

In *BSD, you have [`dtruss`][2] (which use [`dtrace`][3] underlying):

 dtruss -f sh -c 'grep word1 word2 > file.txt'

 [1]: http://linux.die.net/man/1/strace
 [2]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/dtruss.1m.html
 [3]: https://wiki.freebsd.org/DTrace