解释'find -mtime'命令 [英] Explaining the 'find -mtime' command

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

问题描述

我正在尝试删除除最新日期以外的所有带日期的日志.在执行脚本删除文件之前,我当然要测试命令以确保获得正确的结果.

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 results.

执行这些命令时,日期为:

When executing these commands the date is:

Sep  1 00:53:44 AST 2014

目录列表:

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

我认为-mtime +1应该列出一天之内的所有文件.为什么没有列出8-30.log?

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

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

这是理想的效果,但这只是反复试验. 0在说什么?

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

推荐答案

查找规范a>说:

-mtime n 如果从初始化时间中减去的文件修改时间除以86400(任何剩余部分被丢弃),则主数据库应评估为true.

n .

-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.

有趣的是,find的描述未进一步指定初始化时间".但是,可能是find初始化(运行)的时间.

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

在描述中,凡将 n 用作主要参数,均应解释为十进制整数,并可选地以加号('+')或减号('- ')符号,如下所示:

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 超过 n .
   n 完全是 n .
-n 小于 n .

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

在给定的时间(2014-09-01 00:53:44 -4:00,在这里我推断AST是大西洋标准时间,因此从UTC偏移的时区在ISO中是-4:00 8601,但在ISO 9945(POSIX)中为+4:00,但这无关紧要):

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

如此:

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).

因此,为2014-08-30日志文件计算的 n 值恰好是1(该计算是通过整数算术完成的),而+1拒绝该值是因为它严格来说是> 1比较(而不是>= 1).

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).

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

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