1

I have a command which list outs events of "Magento 2", which is working fine in the terminal.

I want it's output to be printed into a file but none of the below code works:

find . -type f -exec grep -n -H -A 2 -T "eventManager->dispatch(" {} \ | tee ~/MAGE2EVENTS.txt

Neither this one:

find . -type f -exec grep -n -H -A 2 -T "eventManager->dispatch(" {} \ >> ~/MAGE2EVENTS.txt

I see 'exec' has been used in this code which shows error:

find: missing argument to `-exec'

So how to print the terminal output of this command to file ?

terdon
  • 100,812
Vicky Dev
  • 433

1 Answers1

2

A -exec command must be terminated with a \; or +. The \; will cause find to run the command once for each file, and the + will make it try and run the command on many files at once, making it more efficient. Since your grep is using -H (print filenames), the + is the better choice. So add + at the end of your find command:

find . -type f -exec grep -n -H -A 2 -T "eventManager->dispatch(" {} + |
     tee ~/MAGE2EVENTS.txt
terdon
  • 100,812
Tung Tran
  • 3,945