Why using dirname in find command gives dots for each match?

前端 未结 7 1466
清酒与你
清酒与你 2021-02-01 15:16

I\'m using find for a task and I noticed that when I do something like this:

find `pwd` -name \"file.ext\" -exec echo $(dirname {}) \\;

it will

7条回答
  •  独厮守ぢ
    2021-02-01 15:42

    It showing you the dots, because the process substitution is evaluated before the command is actually executed. So you've to pass your command into separate shell instance.

    As for workaround, use the following syntax:

    find $PWD -name "file.ext" -exec sh -c 'echo $(dirname {})' ';'
    

    However the easiest way to print or execute something in each directory is by -execdir, e.g.:

    find . -name "file.ext" -execdir pwd ';'
    

提交回复
热议问题