1

In maven local repository directories with dollar name - unresolved properties? I have outlined how I ended up with a few dozen directories that have a dollar sign in their filename.

I tried to get rid of these with the command:

find . -type d -name "*\$*" -exec rm -rf {} \;

which gave an error message for each directory. But the directories and their content were gone never the less.

So I retried things in /tmp:

mkdir "\$adir"
find . -type d -name "*\$*" -exec rm -rf {} \;

and again got an error

find: ./$adir: No such file or directory

How could the files be removed without such a warning?

Stephen Kitt
  • 434,908

1 Answers1

7

This happens because find executes rm -rf on each matching directory, then tries to descend into the directory — but it’s gone.

To avoid this, and not get the corresponding warning, you should tell find to prune the directories, so that it won’t try to process them further:

find . -type d -name "*\$*" -exec rm -rf {} \; -prune

Since rm can process multiple directories, you can tell find to delete multiple directories at a time:

find . -type d -name "*\$*" -exec rm -rf {} + -prune
Stephen Kitt
  • 434,908