我需要在终端中获取文件过去 5 天内的所有修改日期时间戳,所以建议我使用命令来检查。我是 Linux 命令编程的新手,请帮帮我。提前谢谢。
答案1
find /path/to/files -mtime n
是正确的方法,但看看
Numeric arguments can be specified as
+n for greater than n,
-n for less than n,
n for exactly n.
因此,当你对某个时期感兴趣时必须使用前导+
或-
:
要了解 +/- n 如何工作,请检查以下示例:
建议n = 3
和now = 2016/03/15 15:49:00
(24小时制)然后n = 3
指向时间中的某一时刻:
2016/03/15 15:49:00
并n = 3
导致2016/03/12 15:49:00
现在让我们看看哪个前缀指向哪个句点:
-mtime -3 results in now-3*24h until now and the future
(2016/03/12 15:50:00 until all days)
-mtime 3 results in now-4*24h until now-3*24h
(2016/03/11 15:49:01 until 2016/03/12 15:49:59)
-mtime +3 results in all that is older than now-4*24h
(2016/03/11 15:49:00 and before it)
-
因此,前缀、和所产生的句点之间没有重叠
+
。
答案2
您可以使用find
:
find /path/to/directory -mtime 5
替换/path/to/directory
为您要搜索的位置。
后面的数字参数-mtime
(这里是 5)是天数自文件上次修改以来已经过去了。
请注意,由于find
时间戳的四舍五入方式,您可能需要添加一天才能获得正确结果。请参阅man find
以了解更多信息。
-atime n
File was last accessed n*24 hours ago. When find figures out how many
24-hour periods ago the file was last accessed, any fractional part is
ignored, so to match -atime +1, a file has to have been accessed at
least two days ago.
-mtime n
File's data was last modified n*24 hours ago. See the comments
for -atime to understand how rounding affects the interpretation of
file modification times.