Reputation: 733
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?
Upvotes: 5
Views: 1950
Reputation: 181
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.
Upvotes: 4
Reputation: 6124
This seems similar to the question here : Why does find -exec mv {} ./target/ + not work ? (on cygwin)
As pointed by the author, you could use gnu mv
I personally prefer using xargs as shown below :
mkdir old_foo && find . -type d -name "*foo" -print0 | xargs -0 -I {} mv {} new_foo
Upvotes: 4