查找递归超过给定的时间较新的所有文件 [英] Find all files recursively newer than given time

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

问题描述

给定一个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

推荐答案

这是一个有点迂回,因为触摸不采取原始的 time_t的价值,但它应该在脚本中安全地完成这项工作pretty。 (在 -r 选项日期在MacOS X系统present,我已经不是双重检查GNU )。在'时间'变量可以通过直接在触摸写命令替换来避免命令行。

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天全站免登陆