Linux的文件夹删除超过1年,超过3个文件 [英] Linux removing folders older than 1 year and more than 3 files
问题描述
我在写一个Ant脚本来清理存档文件夹
I'm writing an ant script to clean up an archive folder
下面就是我需要把它清理干净:我需要删除超过一定数额的天老的文件夹,并在其中有超过3个文件。因此,举例来说,如果一个文件夹为300天之久,但只有3个文件比它不会被删除。
Here's how I need to clean it up: I need to delete folders old than a certain amount of days AND has more than 3 files in it. So for example if a folder is 300 days old but only has 3 files than it will NOT be deleted.
我知道我可以ssh到归档,并做找到-mtime + 365 -exec室射频{}; \\
删除文件超过1年,但我不知道如何计算最低的3个文件
I know I can ssh into the archive and do find -mtime +365 -exec rm -rf {} ;\
to delete files older than 1 year but I don't know how to account for the minimum of 3 files
我也知道,找到型的F |厕所-l
将列出的文件数,但并没有真正的脚本方面的帮助。
I also know that find -type f | wc -l
will list the number of files, but that doesn't really help in terms of scripting
任何想法?
推荐答案
ANT selectors enable you to customize the fileset to delete.
请尝试以下操作:
<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>
这篇关于Linux的文件夹删除超过1年,超过3个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!