for i in `find . -type d`The new format I use is:
do
# do some processing on the found directory
done
find . -type d | while read iWhile both versions will work in general, the second variant is better for the following reasons:
do
# do some processing on the found directory
done
- It's faster. Namely, in the first case the find command has to finish before processing on directories starts. This isn't noticeable for small directory hierarchies, but it becomes very noticeable for large ones. In the second case the find command outputs results and in parallel while loop picks them up and does processing.
- In case you have spaces embedded in directory names, the second version will work, while the first won't.
Maybe there are some other advantages (or disadvantages) of the second version, but none I can remember at the moment. If you know any, please write it in the comments!