0

I'm trying to remove some folders recursively:

find . -name bin -type d -exec rm -r {} \;

when I run it, I get an output like this:

find: ./Services/BinanceConnector/bin: No such file or directory
find: ./Services/BinanceLeech/bin: No such file or directory
find: ./Services/BitmexConnector/bin: No such file or directory
...

but these are folders that do exist and will get removed.

when I run the command again and the bin folders do not exist, there is nothing printed on the console.

what causes this?


Edit:

ls -ld ./Services/BinanceConnector ./Services/BinanceConnector/bin
drwxr-xr-x  18 thomas  staff  576 Oct 12 21:46 ./Services/BinanceConnector
drwxr-xr-x   3 thomas  staff   96 Oct 12 21:46 ./Services/BinanceConnector/bin
0
2

You can see why this happens if you imagine that find works this way:

  1. make a list of all folders in the current directory

  2. for each one named "bin", run the given command

  3. descend into each folder and start from step 1

In your case, the given command is to remove the folder. Thus when you reach step 3 and try to descend into the folder, it is already gone - giving you the "No such file or directory" warning.

In reality find works in a bit more complicated way, but the above is detailed enough to understand what happens here.

All in all the command will work like you want it to, but you'll get these extra warnings. You can make them go away by adding a -maxdepth 2 option to the command if you know that your directory structure always has the bin folder at that level, or you can use the -prune action to not ensure that the search does not descend into the bin folders.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .