Is there a way to call find recursively?
I would like to search for files matching a given pattern only in directories matching another pattern.
Basically:
for each (sub)directory D matching "*.data"
do
for each file F in directory D (with subdirs) matching "*.important.txt"
do
run command foo on F
done
done
Now, if I leave out the innermost requirement (run command foo in F), it is pretty simple:
find . -type d -name "*.data" \
-exec find \{\} -type f -name "*.important.txt" \;
However, I haven't found a way to pass a command to the inner find.
E.g. the following prints out find: missing argument to `-exec' each time the inner find is called:
find . -type d -name "*.data" \
-exec find \{\} -type f -name "*.important.txt" \
-exec "foo \{\} \;" \;
Any solution should be posix compliant (runnable within a /bin/sh script), esp. I am not looking for solutions that
- wrap the inner find into a separate shell-script
- wrap the inner find into a bash-function
findcalling anotherfindwas... – umläute Apr 07 '16 at 14:39*.dataand then for each file matching*.importantin those directories (without descending) you have to run some command, right ? – don_crissti Apr 07 '16 at 14:41find ... | while read dir; do? – terdon Apr 07 '16 at 15:17{}; empty braces are not special to the shell, and quoting them doesn't change howfindwill "see" them anyway. – Wildcard Apr 21 '16 at 07:58