When I run find with -execdir I don't get the results I was expecting.For example:mkdir -p a/b/cfind . -type d -execdir touch foo \;$ tree aa b  c  foo fooDirectory c does not contain a foo file.How do I get find to visit and do something locally in each directory?
find with -execdir
shell;files;find;directory;directory structure
For every matching file (i.e. every directory), find switches to the directory that contains it (i.e. its parent directory) and executes the specified command. Since the command doesn't use the name of the match, it's never going to act on all the directories. For this particular directory tree, you're doing(cd . && touch foo)        # because ./a matches(cd ./a && touch foo)      # because ./a/b matches(cd ./a/b && touch foo)    # because ./a/b/c matchesTo create a file in every directory, you can simply use -exec instead of -execdir, provided your implementation of find allows {} inside an argument (most do, and in particular I think all the ones ):find . -type d -exec touch {}/foo +For POSIX portability, you would need to do the assembling of the directory name and the file base name manually.find . -type d -exec sh -c 'touch $0/foo' {} \;or (slightly faster)find . -type d -exec sh -c 'for d; do touch $d/foo; done' _ {} +Alternatively, you can use bash's recursive wildcard matching. Beware that (unlike the corresponding feature in ksh and zsh, and unlike your find command) bash recurses under symbolic links to directories.shopt -s globstarfor d in **/*/; do touch -- $d/foo; doneA zsh solution:touch ./**/(e\''REPLY+=foo'\')