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 ?

0
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
1
  • Please mark my answer as the best one if possible. – Tung Tran Dec 4 '15 at 7:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.