Categories
OS tricks

Cleanup directory

So we started running Maven snapshots at a fairly regular basis to enable automatic running of Watir tests. This fills up the disk really fast so I had to do some research to fine a linux command that would delete all but the newest snapshot from multiple projects:

find /var/www/maven2-snapshots -type d -path '*SNAPSHOT' | xargs -i bash -c "find {} -type f -not -path '*maven-metadata*' | grep projectname | sort -r | awk 'NR>6'"

The above command will keep everything that is called maven-metadata something and the 6 latest files in the directory (Maven generates 6 files for each snapshot).

Leave a Reply

Your email address will not be published. Required fields are marked *