I'm trying to stack a find command so that the results it returns only contains files with "warning:" or "error:" text within them. I also require those results in a specific format so I'm using exec stat
for that.
I can get a version of this to work, but I need to be able to use -exec stat
within the while loop to formulate a specific string, and that -exec stat
is making my shell hand me the >
prompt. The part that's not working is in bold below.
Separately I can get these to work. Together I cannot.
Here's an example of one I've got working:
find . -type f -exec grep -li error: {} \; | while read -r file; do ls -l "$file"; done
So now I'm trying to shoehorn that in with another process that limits the files to specific times, types etc. It's not going well:
find /my/directory/here/ -type f -name *.log -mmin -480 -mmin +60 -exec grep -li warning: {} \; -exec grep -li error: {} \; | while read -r file; do -exec stat -c "$file" '%n|%y|%x|%s|%U|%u' {} \; done
Note, the whole thing works if I remove the -exec stat
from within the while loop. If I replace that with a simple ls -l
, results are given back to me. Right now the shell is just giving me a command prompt.
I know I'm not doing this right but I have no ideas right now on what I should be resolving first.
-exec ... {} +
form,find
would collect as many files as possible and then run the command (stat
) on all of them at once (a single or only a few invocations ofstat
). If you change that to-exec ... {} \;
it would runstat
on each file as it gets to it. – Kusalananda Jun 20 '19 at 12:51