find -exec mv tells me No such file or directory

Viewed 1279

if I run:

mkdir -p "$HOME"/old_foo && find "$HOME" -type d -name "*foo" -exec mv -vi {} "$HOME"/new_foo \;

I get:

/Users/medialab/old_foo -> /Users/medialab/new_foo

but also:

find: /Users/medialab/old_foo: No such file or directory

why is find searching for the directory old_foo after it already moved it?

2 Answers

For your question, I think that find try to match the pattern also inside the directory. When find try to enter inside the directory, the directory is not here because he is already moved.

You can see it that if you use :

find "$HOME" -mindepth 1 -maxdepth 1 -type d -name "*foo" -exec mv -vi {} "$HOME"/new_foo \;

The command force the find to stay in your repertory, and don't explore inside all your repertory.

Related