Shell Script — 获取在 <date> 之后修改的所有文件 [英] Shell Script — Get all files modified after &lt;date&gt;

查看:37
本文介绍了Shell Script — 获取在 <date> 之后修改的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我宁愿不在 PHP 中执行此操作,因此我希望精通 shell 脚本的人可以提供帮助.

I'd rather not do this in PHP so I'm hoping a someone decent at shell scripting can help.

我需要一个脚本,它递归地运行目录并查找上次修改日期大于某个日期的所有文件.然后,它将对保留路径信息的文件进行 tar 和 zip.

I need a script that runs through directory recursively and finds all files with last modified date is greater than some date. Then, it will tar and zip the file(s) keeping the path information.

推荐答案

就这么简单:

find . -mtime -1 | xargs tar --no-recursion -czf myfile.tgz

哪里 find .-mtime -1 将选择(递归)当前目录中前一天修改的所有文件.您可以使用分数,例如:

where find . -mtime -1 will select all the files in (recursively) current directory modified day before. you can use fractions, for example:

find . -mtime -1.5 | xargs tar --no-recursion -czf myfile.tgz

这篇关于Shell Script — 获取在 <date> 之后修改的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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