在Linux中,如何删除早于特定日期的文件? [英] How do you delete files older than specific date in Linux?

查看:78
本文介绍了在Linux中,如何删除早于特定日期的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令删除了一年以上的文件.

I used the below command to delete files older than a year.

  find /path/* -mtime +365 -exec rm -rf {} \;

但是现在我想删除所有修改时间早于 2014年1月1日的文件.如何在Linux中执行此操作?

But now I want to delete all files whose modified time is older than 01 Jan 2014. How do I do this in Linux?

推荐答案

您可以将时间戳记作为文件,并将其用作参考点:

You can touch your timestamp as a file and use that as a reference point:

例如对于2014年1月1日:

e.g. for 01-Jan-2014:

touch -t 201401010000 /tmp/2014-Jan-01-0000

find /path -type f ! -newer /tmp/2014-Jan-01-0000 | xargs rm -rf 

之所以可行,是因为 find 有一个我们正在使用的 -newer 开关.

this works because find has a -newer switch that we're using.

man find :

-newer file
       File  was  modified  more  recently than file.  If file is a symbolic
       link and the -H option or the -L option is in effect, the modification time of the 
       file it points to is always used.

这篇关于在Linux中,如何删除早于特定日期的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆