How to print the result of the command, as well as the number of results?

I need to print all the files containing the request specified as a console argument, the next line does this

find . "$path" -type f -name "*$key*" -print

however, I would also like to get the total number of files, but by doing this:

find . "$path" -type f -name "*$key*" -print | wc -l

will give me an account, but not the names of these files, which is not the desired result. How to fix this with a single liner (if possible)?

+4
source share
1 answer

Using the tee command, duplicate the output of the channel and Bash Replace the process as a placeholder for the file to provide a duplicate stream to wc:

$ seq 11 15 | tee >(wc -l)
11
12
13
14
15
5
+4

Source: https://habr.com/ru/post/1678070/


All Articles