I am working on a script that needs to perform an action in every sub-directory of a specific folder.
What is the most efficient way to write that?
for D in `find . -type d`
do
//Do whatever you need with D
done
find . -type d -print0 | xargs -0 -n 1 my_command
the accepted answer will break on white spaces if the directory names have them, and the preferred syntax is $()
for bash/ksh. Use GNU find
-exec
option with +;
eg
find .... -exec mycommand +;
#this is same as passing to xargs
or use a while loop
find .... | while read -r D
do
...
done