在终端中检查过去 5 天内所有文件的修改日期。

在终端中检查过去 5 天内所有文件的修改日期。

我需要在终端中获取文件过去 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 = 3now = 2016/03/15 15:49:00(24小时制)然后n = 3指向时间中的某一时刻:

2016/03/15 15:49:00n = 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.

相关内容