2011-04-28 57 views
1

我想从12小时前删除文件只有12小时前的任何东西我只是想追加。逻辑错误还是有更好的方法?

find . -name "forum*.sql" -mmin +600 -mmin -780 -delete 

有没有像我需要定义的-mmax的东西?

+0

无法解析。 – 2011-04-28 01:52:03

+0

mmin中的最小值代表分钟,而不是最小值。 – Swiss 2011-04-28 04:14:18

回答

0

对不起,但我发现你的描述有点难以解析。

以下代码将删除在12-13小时前完全创建/修改的文件。较旧的文件和较新的文件留在原地。

原谅冗长的var名称,它迟了,我希望他们使这个解决方案自我记录。

# currentTime=201104272232 

TwelveHrsBefore=201104271032 
ThirteenHrsBefore=2001104270932 

# make some zero files with date/time range for what is to be deleted. 
touch -t ${TwelveHrsBefore} upperLimit.tmpFile 
touch -t ${ThirteenHrsBefore} lowerLimit.tmpFile 

find . -name "forum*.sql" -newer lowerLimit.tmpFile -a ! -newer upperLimit.tmpFile 
# when the above is producing the list of files you want to delete, 
# append "| xargs /bin/rm -i" to the end of the find command 
# to delete the files 

# cleanup your tmp files 
rm lowerLimit.tmpFile upperLimit.tmpFile 

该​​可能会令人沮丧得到正确的。我今天已经对它进行了轻微测试,过去我已将这种技术用于生产工作,但我无法访问该代码来查看比此示例更复杂的问题。

我希望这会有所帮助。

相关问题