在 UNIX 中递归地查找最近更新的文件
对于我正在开发的网站,我希望能够在每晚进行 git 提交时自动更新页脚中的“此页面上次修改时间:”部分。本质上,我计划编写一个在每晚午夜运行的 shell 脚本,这将完成我所有的常规服务器维护工作。大多数这些任务我已经知道如何自动化,但我有一个文件(footer.php),它包含在每个页面中,并显示网站上次更新的日期。我希望能够递归地浏览我的网站并检查每个文件的时间戳,然后如果其中任何一个在 footer.php 中的日期之后进行了编辑,我想更新此日期。
我所需要的只是一个 UNIX 命令,该命令将递归地迭代我的文件并仅返回上次修改的日期。我不需要文件名或进行了哪些更改,我只需要知道最近更新的文件被更改的一天(希望是时间)。
我知道使用“ls -l”和“cut”我可以迭代每个文件夹来执行此操作,但我希望有一个运行速度更快且更简单的命令。最好是单行 shell 命令(可能带有 -R 参数)
For a website I'm working on I want to be able to automatically update the "This page was last modified:" section in the footer as I'm doing my nightly git commit. Essentially I plan on writing a shell script to run at midnight each night which will do all of my general server maintenance. Most of these tasks I already know how to automate, but I have a file (footer.php) which is included in every page and displays the date the site was last updated. I want to be able to recursively look through my website and check the timestamp on every file, then if any of these were edited after the date in footer.php I want to update this date.
All I need is a UNIX command that will recursively iterate through my files and return ONLY the date of the last modification. I don't need file names or what changes were made, I just need to know a single day (and hopefully time) that the most recently updated file was changed.
I know using "ls -l" and "cut" I could iterate through every folder to do this, but I was hoping for a quicker-running and easier command. Preferably a single-line shell command (possibly with a -R parameter)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
find
以 Unix 格式输出所有访问时间,然后排序并取最大的。转换为所需的任何日期格式留给读者作为练习:
The
find
outputs all the access times in Unix format, then sort and take the biggest.Converting into whatever date format is wanted is left as an exercise for the reader:
GNU find
检查 find 手册页以使用其他 -printf 说明符。
GNU find
check the find man page to play with other -printf specifiers.
您可能想要查看 inotify 脚本,该脚本会在每次修改任何其他文件时更新页脚,而不是在整个文件系统中查找新的更新。
You might want to look at a inotify script that updates the footer every time any other file is modified, instead of looking all through the file system for new updates.