Skip to content
Advertisement

Find workspace and delete everything with the name, except for filename and everything in a directory pattern

I’m trying to create a cronjob that will delete everything with a pattern *.jar, except for master.jar and anything in a directory pattern */jarkeeper/*/staging/*

I’m close but not luck in finding the correct command. Here’s what i have so far:

find /var/lib/jenkins/workspace/ ! -path "*/jarkeeper/*/staging/*" -or -type f ! -name master.jar -name *.jar

and

find /var/lib/jenkins/workspace/ ( ! -path "*/jarkeeper/*/staging/*" ) -or ( -type f ! -name master.jar ) -name *.jar

What should the correct format be?

Advertisement

Answer

The issue looks like you are using -or as opposed to -or. I would also suggest using -path as opposed to -name throughout to keep everything consistent and so:

find /var/lib/jenkins/workspace/ -type f ! -path "*master.jar" -or ! -path "*/jarkeeper/*/staging/*" -or -path "*.jar"
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement