删除特定日期文件_删除早于特定日期的文件

删除特定日期文件

删除特定日期文件

Have you ever needed to clean out some old files out of a folder? This is especially useful when you are trying to keep a log directory from getting too bloated with files, and Linux makes it really easy to clear out the junk.

您是否曾经需要从文件夹中清除一些旧文件? 当您试图避免日志目录中文件太过膨胀时,此功能特别有用,而Linux使得清除垃圾邮件确实非常容易。

We’ll just use the find command to search for all the files older than a certain date, and then use the –exec command to delete them. You could use the –delete command instead, but you’ll end up with a maximum arguments when there are too many files.

我们将只使用find命令搜索所有早于特定日期的文件,然后使用–exec命令将其删除。 您可以改用–delete命令,但是当文件太多时,最终将得到最大参数。

Find Command Syntax

查找命令语法

find /path/to/files* -mtime +5 -exec rm {} ;

查找/ path / to / files * -mtime +5 -exec rm {};

Note that there are spaces between rm, {}, and ;

请注意,rm,{}和;之间有空格。

Explanation for Command

命令说明

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.

    第一个参数是文件的路径。 如上例所示,它可以是路径,目录或通配符。 我建议使用完整路径,并确保在不执行exec的情况下运行该命令,以确保获得正确的结果。
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.

    第二个参数-mtime用于指定文件存在的天数。 如果输入+5,它将查找5天以上的文件。
  • The third argument, -exec, allows you to pass in a command such as rm. The {} ; at the end is required to end the command.

    第三个参数-exec允许您传递诸如rm之类的命令。 {}; 最后需要结束命令。

This pretty much works on any ‘nix distribution.

这几乎适用于任何'nix发行版。

翻译自: https://www.howtogeek.com/50211/delete-files-older-than-a-certain-date/

删除特定日期文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值