击:删除基于文件的日期戳 [英] Bash: delete based on file date stamp

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

问题描述

我有一堆文件的文件夹。我需要删除7月1日之前创建的所有文件。我该怎么做,在bash脚本?

I have a folder with a bunch of files. I need to delete all the files created before July 1st. How do I do that in a bash script?

推荐答案

我觉得以下应该做你想要什么:

I think the following should do what you want:

touch -t 201007010000 dummyfile
find /path/to/files -type f ! -newer dummyfile -delete

第一行创建这是最后一次修改1日2010年7月它有一个日期不超过dummyfile新文件的第二行中找到/路径下的所有文件/到/文件,然后删除它们。

The first line creates a file which was last modified on the 1st July 2010. The second line finds all files in /path/to/file which has a date not newer than the dummyfile, and then deletes them.

如果您要仔细检查其是否正常工作,然后删除 -delete 参数,它应该只列出其将被删除的文件。

If you want to double check it is working correctly, then drop the -delete argument and it should just list the files which would be deleted.

这篇关于击:删除基于文件的日期戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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