0

What I have:

/usr/bin/find /my_directory -type f -not -empty -name '*.log' -printf '%T@ %Tc %p\n' -exec grep 'text in file' {} \;

This will show all non-empty log files in /my_directory:

1619942263.2701036230 Sun May  2 09:57:43 2021 /my_directory/abc.log
1619945861.8521817540 Sun May  2 10:57:41 2021 /my_directory/def.log

But I only want to get files with text in file - in this or a similar style.

3

Place -exec before -printf:

find /my_directory -type f -not -empty -name '*.log' -exec grep -q 'text in file' {} \; -printf '%T@ %Tc %p\n'

-exec evaluates to false if the command exits with a non-zero exit code, and subsequent actions are skipped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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