I'd like to run a find command and process the files it returns, but also echo a count of the files processed as it goes, to give me a sense of its progress.

Right now, my command is (as an example):

COUNT=0\; find . -name '*.*' -exec echo "$COUNT: \c" \; -exec echo {} \;

But as a result, I don't get the count to echo (and I can't figure out how to increment it). I'd like it to give me something like:

0: ./FileOne.txt
1: ./FileTwo.txt
205: ./FileTwoHundredAndFive.txt

1 Answer 1


The commands executed by find are independent. Each -exec starts a new command. There's no way to transfer the current count from one command to the next, except by storing it somewhere (in a file) which would be very slow.

You can make find print something each time it sees a file, and pipe the output to a program that counts the input lines.

find … -print -exec 'the stuff you want to do' | nl

This will print counts after a delay due to buffering. See Turn off buffering in pipe on turning off buffering.

stdbuf -oL -eL find … -print -exec 'the stuff you want to do' | nl
  • Was afraid that was the case. I was hoping to avoid calling a script for such a dumb function, but if that's the only way, that's the only way. Thanks! Oct 3, 2016 at 0:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .