2 added 731 characters in body
source | link
find ./ -name "example.xml" -newermt "2018-01-01" -exec grep -r "videoplayer.1" /. \;

This would find, starting at the current directory ./, files with the -name example.xml that are newer (in modification time) than 2018-01-01 and for each of them, execute the command grep -r "videoplayer.1" /..

But we see that the grep command does not take the file name found by find into account, but instead the command is always constant. Furthermore, it starts a recursive (-r) search from the root of the filesystem (/.). Now, that may be a typo (./ vs. /.), but the meaning changes completely.

Even with grep -r ... ./, the search would be recursive starting from the current directory, and with -exec, that's the directory where find was started.

With find -exec, you need to use the {} placeholder to tell find where to insert the filename currently being processed. So

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep  "videoplayer.1" {} \;

To run grep videoplayer.1 filename on all files named example.xml that are newer than January 1st 2018.

Actually, you could do replace the \; that terminates the -exec command with a + to have find pass multiple files to one invocation of grep. That would make the whole job faster, since less processes need to be started:

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep  "videoplayer.1" {} \+

Also, if you want to make sure grep lists the name of the file it's processing, you can use the -H flag (in at least GNU and BSD grep):

  -H, --with-filename       

Print the file name for each match. This is the default when there is more than one file to search.

(An alternative to -H would be to add something like /dev/null to the list of files given to grep)

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep -r "videoplayer.1" /. \;

This would find, starting at the current directory ./, files with the -name example.xml that are newer (in modification time) than 2018-01-01 and for each of them, execute the command grep -r "videoplayer.1" /..

But we see that the grep command does not take the file name found by find into account, but instead the command is always constant. Furthermore, it starts a recursive (-r) search from the root of the filesystem (/.). Now, that may be a typo (./ vs. /.), but the meaning changes completely.

Even with grep -r ... ./, the search would be recursive starting from the current directory, and with -exec, that's the directory where find was started.

With find -exec, you need to use the {} placeholder to tell find where to insert the filename currently being processed. So

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep  "videoplayer.1" {} \;

To run grep videoplayer.1 filename on all files named example.xml that are newer than January 1st 2018.

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep -r "videoplayer.1" /. \;

This would find, starting at the current directory ./, files with the -name example.xml that are newer (in modification time) than 2018-01-01 and for each of them, execute the command grep -r "videoplayer.1" /..

But we see that the grep command does not take the file name found by find into account, but instead the command is always constant. Furthermore, it starts a recursive (-r) search from the root of the filesystem (/.). Now, that may be a typo (./ vs. /.), but the meaning changes completely.

Even with grep -r ... ./, the search would be recursive starting from the current directory, and with -exec, that's the directory where find was started.

With find -exec, you need to use the {} placeholder to tell find where to insert the filename currently being processed. So

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep  "videoplayer.1" {} \;

To run grep videoplayer.1 filename on all files named example.xml that are newer than January 1st 2018.

Actually, you could do replace the \; that terminates the -exec command with a + to have find pass multiple files to one invocation of grep. That would make the whole job faster, since less processes need to be started:

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep  "videoplayer.1" {} \+

Also, if you want to make sure grep lists the name of the file it's processing, you can use the -H flag (in at least GNU and BSD grep):

  -H, --with-filename       

Print the file name for each match. This is the default when there is more than one file to search.

(An alternative to -H would be to add something like /dev/null to the list of files given to grep)

1
source | link

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep -r "videoplayer.1" /. \;

This would find, starting at the current directory ./, files with the -name example.xml that are newer (in modification time) than 2018-01-01 and for each of them, execute the command grep -r "videoplayer.1" /..

But we see that the grep command does not take the file name found by find into account, but instead the command is always constant. Furthermore, it starts a recursive (-r) search from the root of the filesystem (/.). Now, that may be a typo (./ vs. /.), but the meaning changes completely.

Even with grep -r ... ./, the search would be recursive starting from the current directory, and with -exec, that's the directory where find was started.

With find -exec, you need to use the {} placeholder to tell find where to insert the filename currently being processed. So

find ./ -name "example.xml" -newermt "2018-01-01" -exec grep  "videoplayer.1" {} \;

To run grep videoplayer.1 filename on all files named example.xml that are newer than January 1st 2018.