开发者

Bash: delete based on file date stamp

I have a folder with a bunch of files. I need to delete all the files creat开发者_如何学运维ed 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

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.

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.


This should work:

find /file/path ! -newermt "Jul 01"

To find the files you want to delete, so the command to delete them would be:

find /file/path ! -newermt "Jul 01" -type f -print0 | xargs -0 rm
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜