Linux deletes folders older than 1 year and more than 3 files

I am writing ant script to clean archive folder

Here's how I need to clean it: I need to delete old folders than a certain number of days, and it contains more than 3 files. For example, if a folder is 300 days but has only 3 files, it will not be deleted.

I know that I can make ssh in the archive and do find -mtime +365 -exec rm -rf {} ;\ to delete files older than 1 year, but I do not know how to account for at least 3 files

I also know that find -type f | wc -l find -type f | wc -l will list the number of files, but this does not help in terms of scripts

Any ideas?

+4
source share
1 answer

ANT selectors allows you to configure a set of files for deletion.

Try the following:

 <target name="purge"> <tstamp> <format property="touch.time" pattern="MM/dd/yyyy hh:mm aa" offset="-300" unit="day"/> </tstamp> <delete> <fileset dir="${src.dir}"> <date datetime="${touch.time}" when="before"/> <scriptselector language="javascript"><![CDATA[ if (file.getParentFile().list().length > 3) { self.setSelected(true); } else { self.setSelected(false); } ]]> </scriptselector> </fileset> </delete> </target> 
+4
source

All Articles