Find files by file modification time and found empty folder

Source: Internet
Author: User
Tags chmod min backup

Find files that were modified two days ago:

Find. -type f-mtime-2

Find files that have been modified within 3 days:

Find-ctime-3

Find command uses more than 6 days, empty file Independent query command:

Find/data/backup-ctime +6-exec rm-f {}; Delete files in the/data/backup directory that have been modified for more than 6 days.

Find/data/backup-type d-empty-exec rmdir {}; >/dev/null 2>&1 deletes the empty folder under the/data/backup directory, outputting both the correct and error messages to the null.

Find command for more than 6 days and empty files:

Find./-type d-empty-ctime +6

To find a file by modification time, use the option-mtime:

Find/home/admin-mtime-1 #查找/home/admin Directory to modify the file within 1 days

Find/home/admin-name *.txt-mtime-1 #查找/home/admin directory file with a. txt end of the modified time within 1 days

Find files by file modification time

---(+n)----------|----------(n)----------|----------(-N)---

(n+1) before *24h | (n+1) *24h~n*24h between |n*24h

-ctime-n find files that have been modified from the current n*24h

-ctime n Find files that have been modified (n+1) *24h before now n*24h

-ctime +n Find files that have been modified before (n+1) *24h now

[A|c|m]min [Last visit | final Status Modification | Final content Modification]min

[A|c|m]time [Last visit | final Status Modification | Final content Modification]time

Three times of Linux files (find for example):

Atime last access time, such as LS, more, but chmod, chown, LS, stat, etc. will not modify some time, use Ls-utl can be viewed in this chronological order;

CTime Last state modification time, such as chmod, Chown and other state time changes but the modification time will not change, using stat file can be viewed;

Mtime Last content modification time, such as VI after saving, change time changes, Atime and CTime also change accordingly.

Attention:

The creation time of a file is not recorded in Linux unless the file has not changed since it was created, and its creation time is the last time it was modified.

#ls-lt/home/admin # View in modified chronological order

#ls-lut/home/admin # View by Access time order

(If you want to reverse-order view, you need to add an option-R)

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.