Search code examples
linuxmavencygwin

How to clean up all maven projects with linux find command?


I want to clean up all my maven projects at once. But I want to avoid to do it step-by-step going through all the folders manually and call mvn clean. So I thought to do this with the find command. I tried the following call:

find . -name pom.xml -exec mvn clean {} \;

The result was the error message: find: missing argument for "-exec".

Now my question: is it possible to do such a call with find and exec? I thought I can use every command as an argument for find -exec.

Thanks in advance
Hardie


Solution

  • If you expand what exec will run for you:

    mvn clean dir1/dir2/pom.xml
    

    You'll see that you treated the pom-file as a maven goal.

    You should use -f flag, and apostrophes (to prevent globing):

    find . -name pom.xml -exec mvn clean -f '{}' \;
    

    As for me, I use this command

    find . -name 'target' -a -type d -exec rm -rfv '{}' \;
    

    This will delete all target folders.