解释发现-mtime命令 [英] Explaining find -mtime command

查看:134
本文介绍了解释发现-mtime命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除除了最近所有的dateed日志。在我执行一个脚本来删除这些文件,我想,当然测试我的命令,以确保我拉扯大准确resuts。

在执行这些命令的日期是:

  09月01日0点53分44秒2014年AST

目录列表:

  8月27日23:59 testfile.2014-08-27.log
8月28日23:59 testfile.2014-08-28.log
8月29日23:59 testfile.2014-08-29.log
8月30日23:59 testfile.2014-08-30.log
8月31日23:59 testfile.2014-08-31.log
9月1日00:29 testfile.log

我想-mtime +1应该列出所有文件过了一天了。为什么没有8-30.log上市?

 找到。型的F -mtime +1 -nametestfile的*日志
./testfile.2014-08-27.log
./testfile.2014-08-28.log
./testfile.2014-08-29.log

这是预期的效果,但它只是试验和错误。这是什么说法0?

 找到。型的F -mtime + 0 -nametestfile的*日志
./testfile.2014-08-30.log
./testfile.2014-08-27.log
./testfile.2014-08-28.log
./testfile.2014-08-29.log


解决方案

的POSIX规范找到说:


  

-mtime N
      如果从初始化时间减去文件修改时间,由86400分(与任何剩余废弃),是主应评估为true的 N 的。


有趣的是,的描述中找到并没有进一步明确初始化时间。这可能是,不过,时间找到初始化(运行)。


  

在说明,无论的 N 的使用作为主要的参数,它应是PTED为十进制整数间$ P $可选$ p $由加pceded('+')或减号( - )标志,如下所示:


  
  

+ N
      超过的 N 的。结果
    的 N
      确切的 N 的。结果
  的 -n
      小于的 N 的。


在给定的时间(2014年9月1日0时53分44秒-4:00,在那里我推断出AST是大西洋标准时间,因此,时区UTC的偏移量为-4:00在ISO 8601 +4不过:在ISO 9945(POSIX)00,但它并不重要,所有的东西):

  1409547224 = 2014年9月1日0时53分44秒-04:00
1409457540 = 2014年8月30日23:59:00 -04:00

这样:

  1409547224  -  1409457540 = 89684
86400分之89684= 1

即使秒时代以来的价值观是错误的,相对值是正确的(对于在世界某个地方一段时间区,它们是正确的)。

N 的为2014年8月30日的日志文件计算出的值,因此是完全 1 (计算是整数运算完成),以及 +1 拒绝它,因为它是严格意义上的> 1 比较(而不是> = 1 )。

I'm trying to remove all the dateed logs except the most recent. Before I execute a script to remove the files, I want to of course test my commands to make sure I'm bringing up accurate resuts.

When executing these commands the date is:

Sep  1 00:53:44 AST 2014

Directory Listing:

Aug 27 23:59 testfile.2014-08-27.log
Aug 28 23:59 testfile.2014-08-28.log
Aug 29 23:59 testfile.2014-08-29.log
Aug 30 23:59 testfile.2014-08-30.log
Aug 31 23:59 testfile.2014-08-31.log
Sep  1 00:29 testfile.log

I thought -mtime +1 was supposed to list all files over a day old. Why isn't the 8-30.log listed?

find . -type f -mtime +1 -name "testfile*log"
./testfile.2014-08-27.log
./testfile.2014-08-28.log
./testfile.2014-08-29.log

This is the desired effect, but it was just trial and error. What is this 0 saying?

find . -type f -mtime +0 -name "testfile*log"
./testfile.2014-08-30.log
./testfile.2014-08-27.log
./testfile.2014-08-28.log
./testfile.2014-08-29.log

解决方案

The POSIX specification for find says:

-mtimen The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.

Interestingly, the description of find does not further specify 'initialization time'. It is probably, though, the time when find is initialized (run).

In the descriptions, wherever n is used as a primary argument, it shall be interpreted as a decimal integer optionally preceded by a plus ( '+' ) or minus-sign ( '-' ) sign, as follows:

+n More than n.
  n Exactly n.
-n Less than n.

At the given time (2014-09-01 00:53:44 -4:00, where I'm deducing that AST is Atlantic Standard Time, and therefore the time zone offset from UTC is -4:00 in ISO 8601 but +4:00 in ISO 9945 (POSIX), but it doesn't matter all that much):

1409547224 = 2014-09-01 00:53:44 -04:00
1409457540 = 2014-08-30 23:59:00 -04:00

so:

1409547224 - 1409457540 = 89684
89684 / 86400 = 1

Even if the 'seconds since the epoch' values are wrong, the relative values are correct (for some time zone somewhere in the world, they are correct).

The n value calculated for the 2014-08-30 log file therefore is exactly 1 (the calculation is done with integer arithmetic), and the +1 rejects it because it is strictly a > 1 comparison (and not >= 1).

这篇关于解释发现-mtime命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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