Mtime in find, in work (always changing Series 5)

Source: Internet
Author: User

I will keep "changing the series all the time" until I leave the company and change it.

At work today, I want to write a script to delete files that are not 7 days away.

Use Find-name "[0-9] [0-9] [0-9] [0-9]"-type D-mtime + 7 | RM-RF {}/

Similar to the above, we found that the role of + 7 was not reflected, and the file was not deleted seven days ago. After checking the information on the Internet, I was misled to use the 24-hour computation and found that it was not correct. Then I thought about the experiment myself:

Discovery-7 represents the current-7th days
7 represents 7th-8th days

+ 7 represents 8th days later

Of course, the time is indeed calculated by 24 hours, because it is necessary to push back from the current time.

The knowledge shared by someone on the internet is finally the same as I thought:

Find-MtimeThe use of this parameter is indeed a mistake I have made before. Someone asked me this question again today. I think it is necessary to record this question here. the mtime parameter is described as follows:
- mtime N: Find the file based on the file change time. N is an integer.
N indicates that the file change time is n days,-N indicates that the file change time is less than N days, and + N indicates that the file change time is earlier than N days.
for example,
- mtime 0
indicates that the file modification time is 0 days away from the current time, that is, files less than one day (24 hours) from the current time.
- mtime 1
indicates a file whose modification time is one day away from the current file, that is, the file from the current time 1 day (24 hours-48 hours.
- mtime + 1 indicates that the file is modified for more than one day, that is, two days (48 hours) from the current time) files other than
- mtime -1 indicates that the file modification time is less than one day, that is, one day (24 hours) from the current time)

Why- mtime + 1
indicates that the file was modified for more than one day, that is, the file is 48 hours away from the current time, instead of 24 hours away?
because the N value can only be an integer, that is, the nearest integer greater than 1 is 2, all- mtime + 1 is not more than one day (24 hours) than the current time, but more than two days (48 hours) than the current time ). The same applies to other atime ctime methods!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.