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?

0

1 Answer 1

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 
3
  • thx for the quick answer - that's very helpful in the context of this maven misbehavior Commented Sep 21, 2018 at 13:31
  • 2
    ... or use depth-first traversal with -depth. Commented Sep 21, 2018 at 13:40
  • @Kusalananda but that ends up doing more work (visiting all the contents of directories which will be deleted, and deleting child directories which would be deleted with one of their parents). Commented Sep 21, 2018 at 13:45

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.