How to use wc command with find and exec commands

I use the following command to calculate md5sum for each file in the selected directory and log results to the file:

find $myDir -type f -exec md5sum "{}" ; >> $myLog

I would like to also count processed element using wc command. How to achieve that ?

Asked By: Irbis

find "$myDir" -type f -exec md5sum {} + | tee -a -- "$myLog" | wc -l

tee -a will add the output of your find command to the file, and also to your stdout, where you can process it further, for instance with wc -l to count the number of lines in the input (and as md5sum escapes newline characters in file names as n, that will also be the number of files that were processed).

Answered By: aviro
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.