The following command
mkdir -p /tmp/test/foo /tmp/test/bar && \
find /tmp/test/ -mindepth 1 -type d \
-exec echo Deleting "{}" \; \
-exec rm -rv "{}" \;
I'd expect to print
Deleting /tmp/test/foo
removed directory '/tmp/test/foo'
Deleting /tmp/test/bar
removed directory '/tmp/test/bar'
(per 1st -exec statement)
and delete respective directories (per 2nd -exec statement).
Well, technically this is indeed what's happening and being printed on stdout - but there're 2 additional lines on stderr.
Deleting /tmp/test/foo
removed directory '/tmp/test/foo'
find: ‘/tmp/test/foo’: No such file or directory
Deleting /tmp/test/bar
removed directory '/tmp/test/bar'
find: ‘/tmp/test/bar’: No such file or directory
So it /seems/ the 2nd -exec-statement calling rm -rv is issued twice.
- Why / What's exactly happening here?
- How do I achieve what I'd actually expect from above command?
findis wanting to enter the directories to see if there is any work to be done in them. Add a-depthflag to do a depth-first walk of the tree?