Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the meaning of the-mtime parameter of the find command

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about the meaning of the-mtime parameter of the find command, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

The true meaning of the-mtime parameter of find has not been understood before.

I happened to be talking about this with a classmate today.

I often use the parameter-mtime when I write shell scripts and delete some files regularly, so I'm going to take a good look at it and figure it out.

The explanation in man find:

-mtime n

File's data was last modified 24 hours ago. See the comments for-atime to understand how

Rounding affects the interpretation of file modification times.

-atime n

File was last accessed 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.

Find $HOME-mtime 0

Search for files in your home directory which have been modified in the last twenty-four hours. This

Command works this way because the time since each file was last modified is divided by 24 hours and any

Remainder is discarded. That means that to match-mtime 0, a file will have to have a modification in

The past which is less than 24 hours ago.

The following list of files is used for experiments

[oracle@goolen arch] $ll-h

Total 1.1G

-rw-r- 1 oracle oinstall 40M Apr 29 22:00 archive_1_53_844522225.arc

-rw-r- 1 oracle oinstall 45m Apr 29 22:29 archive_1_54_844522225.arc

-rw-r- 1 oracle oinstall 38m Apr 30 16:30 archive_1_55_844522225.arc

-rw-r- 1 oracle oinstall 38m Apr 30 16:35 archive_1_56_844522225.arc

-rw-r- 1 oracle oinstall 42m Apr 30 22:00 archive_1_57_844522225.arc

-rw-r- 1 oracle oinstall 45m Apr 30 22:36 archive_1_58_844522225.arc

-rw-r- 1 oracle oinstall 38m May 1 14:00 archive_1_59_844522225.arc

-rw-r- 1 oracle oinstall 38m May 1 22:00 archive_1_60_844522225.arc

-rw-r- 1 oracle oinstall 41m May 1 22:37 archive_1_61_844522225.arc

-rw-r- 1 oracle oinstall 41m May 222: 00 archive_1_62_844522225.arc

-rw-r- 1 oracle oinstall 45m May 22238 archive_1_63_844522225.arc

-rw-r- 1 oracle oinstall 42m May 3 06:00 archive_1_64_844522225.arc

-rw-r- 1 oracle oinstall 40M May 3 14:09 archive_1_65_844522225.arc

-rw-r- 1 oracle oinstall 45m May 3 22:39 archive_1_66_844522225.arc

-rw-r- 1 oracle oinstall 39m May 4 06:00 archive_1_67_844522225.arc

-rw-r- 1 oracle oinstall 38m May 4 17:00 archive_1_68_844522225.arc

-rw-r- 1 oracle oinstall 45m May 5 08:10 archive_1_69_844522225.arc

-rw-r- 1 oracle oinstall 45m May 5 10:28 archive_1_70_844522225.arc

-rw-r- 1 oracle oinstall 6.7m May 5 14:57 archive_1_71_844522225.arc

-rw-r- 1 oracle oinstall 38m May 522: 00 archive_1_72_844522225.arc

-rw-r- 1 oracle oinstall 38m May 6 08:28 archive_1_73_844522225.arc

-rw-r- 1 oracle oinstall 38m May 6 14:00 archive_1_74_844522225.arc

-rw-r- 1 oracle oinstall 39m May 6 22:00 archive_1_75_844522225.arc

-rw-r- 1 oracle oinstall 45m May 7 08:29 archive_1_76_844522225.arc

-rw-r- 1 oracle oinstall 38m May 7 22:00 archive_1_77_844522225.arc

-rw-r- 1 oracle oinstall 38m May 8 05:00 archive_1_78_844522225.arc

-rw-r- 1 oracle oinstall 38m May 8 09:00 archive_1_79_844522225.arc

[oracle@goolen arch] $date

Thu May 8 16:29:09 CST 2014

+ + it's 16:30 on May 8th

+ + Let's first take a look at the output of the parameter-mtime + 1:

[oracle@goolen arch] $find. / *-name "* .arc"-mtime + 1-exec ls-l {}\

-rw-r- 1 oracle oinstall 41009664 Apr 29 22:00. / archive_1_53_844522225.arc

-rw-r- 1 oracle oinstall 46589440 Apr 29 22:29. / archive_1_54_844522225.arc

-rw-r- 1 oracle oinstall 39376384 Apr 30 16:30. / archive_1_55_844522225.arc

-rw-r- 1 oracle oinstall 39756800 Apr 30 16:35. / archive_1_56_844522225.arc

-rw-r- 1 oracle oinstall 43597312 Apr 30 22:00. / archive_1_57_844522225.arc

-rw-r- 1 oracle oinstall 46589440 Apr 30 22:36. / archive_1_58_844522225.arc

-rw-r- 1 oracle oinstall 39395328 May 1 14:00. / archive_1_59_844522225.arc

-rw-r- 1 oracle oinstall 39623168 May 1 22:00. / archive_1_60_844522225.arc

-rw-r- 1 oracle oinstall 42701824 May 1 22:37. / archive_1_61_844522225.arc

-rw-r- 1 oracle oinstall 42967040 May 222: 00. / archive_1_62_844522225.arc

-rw-r- 1 oracle oinstall 46589440 May 22238. / archive_1_63_844522225.arc

-rw-r- 1 oracle oinstall 43959808 May 3 06:00. / archive_1_64_844522225.arc

-rw-r- 1 oracle oinstall 41638400 May 3 14:09. / archive_1_65_844522225.arc

-rw-r- 1 oracle oinstall 46589440 May 3 22:39. / archive_1_66_844522225.arc

-rw-r- 1 oracle oinstall 39922176 May 4 06:00. / archive_1_67_844522225.arc

-rw-r- 1 oracle oinstall 39352832 May 4 17:00. / archive_1_68_844522225.arc

-rw-r- 1 oracle oinstall 46589440 May 5 08:10 / archive_1_69_844522225.arc

-rw-r- 1 oracle oinstall 46373888 May 5 10:28 / archive_1_70_844522225.arc

-rw-r- 1 oracle oinstall 7001600 May 5 14:57 / archive_1_71_844522225.arc

-rw-r- 1 oracle oinstall 39364608 May 522: 00. / archive_1_72_844522225.arc

-rw-r- 1 oracle oinstall 39477248 May 6 08:28. / archive_1_73_844522225.arc

-rw-r- 1 oracle oinstall 39361024 May 6 14:00. / archive_1_74_844522225.arc

The list of files returned by the + + command is archive_1_53_844522225.arc-archive_1_74_844522225.arc

In terms of time, it is up to 14:00 on May 6th.

There is another file generated at 22:00 in the evening on May 6th, which is not in the output.

-rw-r- 1 oracle oinstall 39m May 6 22:00 archive_1_75_844522225.arc

According to my previous understanding (wrong),-mtime + 1, the output should be all the files before May 7, but there is no output of the archive_1_75_844522225.arc generated at 22:00 in the evening on the 6th.

The correct explanation:

-mtime+1 indicates a file whose modification time is more than 1 day, that is, a file other than 2 days (48 hours) from the current time

This also explains why the file generated at 22:00 on the 6th was not output.

Why is-mtime + 1 outside 48 hours instead of 24 hours? because n can only be an integer, and the next integer greater than 1 is 2, so it is outside 48 hours.

Let's look at the output of-mtime 1:

[oracle@goolen arch] $find. / *-name "* .arc"-mtime 1-exec ls-l {}\

-rw-r- 1 oracle oinstall 40737280 May 6 22:00. / archive_1_75_844522225.arc

-rw-r- 1 oracle oinstall 46589440 May 7 08:29. / archive_1_76_844522225.arc

The output is archive_1_75_844522225.arc generated at 22:00 on the 6th and archive_1_76_844522225.arc generated at 8: 29 on the 7th.

Explanation:

-mtime 1 indicates a file whose modification time is currently 1 day, that is, a file that is 1 day (24 hours-48 hours) from the current time

Let's look at the output of-mtime 0:

[oracle@goolen arch] $find. / *-name "* .arc"-mtime 0-exec ls-l {}\

-rw-r- 1 oracle oinstall 39303680 May 7 22:00. / archive_1_77_844522225.arc

-rw-r- 1 oracle oinstall 39483392 May 8 05:00. / archive_1_78_844522225.arc

-rw-r- 1 oracle oinstall 39208448 May 8 09:00. / archive_1_79_844522225.arc

Explanation:

-mtime 0 indicates a file whose modification time is 0 days from the current time, that is, a file less than 1 day (24 hours) from the current time

Let's look at the output of-mtime-1:

[oracle@goolen arch] $find. / *-name "* .arc"-mtime-1-exec ls-l {}\

-rw-r- 1 oracle oinstall 39303680 May 7 22:00. / archive_1_77_844522225.arc

-rw-r- 1 oracle oinstall 39483392 May 8 05:00. / archive_1_78_844522225.arc

-rw-r- 1 oracle oinstall 39208448 May 8 09:00. / archive_1_79_844522225.arc

Explanation:

-mtime-1 indicates a file whose modification time is less than 1 day, that is, a file within 1 day (24 hours) from the current time

After reading the above, do you have any further understanding of the meaning of the-mtime parameter of the find command? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report