bash 基于日期创建 ZIP 文件,Linux
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27481955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create ZIP of files based on date, Linux
提问by user984003
I am creating a zip file of some files (image files), but need to limit it such that only the latest files are added to the zip file. I need files that are more than 2 days old. Exact time is not relevant.
我正在创建一些文件(图像文件)的 zip 文件,但需要对其进行限制,以便仅将最新文件添加到 zip 文件中。我需要超过 2 天的文件。确切的时间无关紧要。
This is what I have been doing, but how do I limit it based on date? This is Linux and is run from a batch .sh file.
这就是我一直在做的事情,但是如何根据日期对其进行限制?这是 Linux,从批处理 .sh 文件运行。
zip -r /destination_path/media_backup.zip /from_path/media
回答by Josh Jolly
Do you want the latest files or the files that are older than 2 days? Either way you can use the same basic command:
您想要最新的文件还是早于 2 天的文件?无论哪种方式,您都可以使用相同的基本命令:
zip -r /destination_path/media_backup.zip $(find /from_path/media -type f -mtime +2)
You just need to adjust the mtime
option according to your requirements. +X
means "last modified more than X days ago", -X
would be "last modified less than X days ago". If you need more resolution, you could use -mmin
instead, which checks against minutes rather than days.
您只需要mtime
根据您的要求调整选项。+X
表示“上次修改多于 X 天前”,-X
将是“上次修改少于 X 天前”。如果您需要更多分辨率,则可以-mmin
改用,它会根据分钟而不是天进行检查。
回答by Ifechi
Try this.
尝试这个。
zip -rtt 2014-12-13 /destination_path/media_backup.zip /from_path/media
You can find more options using the zip man page.
您可以使用 zip 手册页找到更多选项。
-tt Do not operate on files modified after or at the specified date
回答by Bhargav Modi
this should work, M not sure and I had not tried.
这应该有效,我不确定,我还没有尝试过。
find / -mtime +2 -ls > input.txt
cat input.txt | zip myzipfile.zip -@