递归查找比给定时间新的所有文件 [英] Recursively find all files newer than a given time

查看:47
本文介绍了递归查找比给定时间新的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个time_t:

Given a time_t:

⚡ date -ur 1312603983
Sat  6 Aug 2011 04:13:03 UTC

我正在寻找一种bash单线版,其中列出了所有较新的文件.比较时应考虑时区.

I'm looking for a bash one-liner that lists all files newer. The comparison should take the timezone into account.

类似

find . --newer 1312603983

但是使用time_t而不是文件.

But with a time_t instead of a file.

推荐答案

这有点circuit回,因为touch不会使用原始的time_t值,但它应该在脚本中相当安全地完成工作. (date-r选项在MacOS X中存在;我没有仔细检查过GNU.)可以通过直接在touch命令行中编写命令替换来避免使用"time"变量. >

This is a bit circuitous because touch doesn't take a raw time_t value, but it should do the job pretty safely in a script. (The -r option to date is present in MacOS X; I've not double-checked GNU.) The 'time' variable could be avoided by writing the command substitution directly in the touch command line.

time=$(date -r 1312603983 '+%Y%m%d%H%M.%S')
marker=/tmp/marker.$$
trap "rm -f $marker; exit 1" 0 1 2 3 13 15
touch -t $time $marker
find . -type f -newer $marker
rm -f $marker
trap 0

这篇关于递归查找比给定时间新的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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