I’m on a linux system I wonder what is wrong with the following execution of find:
mkdir a && touch a/b
find . -name a -type d -exec echo '{}' \;
./a
find . -name a -type d -exec rm -r '{}' \;
find: `./a': No such file or directory
The invocation of echo is just for testing purposes. I would expect the last command to remove the directory ‘./a’ entirely and return 0. Instead it removes the directory and generates the error message. To repeat, it does remove the directory! What is going on?
rmexecutes without a problem. The issue is thatfindis confused, since it knew the directory./awas there, it tries to visit that directory to look for directories nameda. However, find cannot enter the directory, since it was already removed.One way to avoid this is to do
This will let the find move along before the
rmcommand is executed. Or, you can simply ignore the error in your original command.