Use Shell to delete files from three days ago or three days in Linux

Source: Internet
Author: User

Description: +n is greater than N,-n is less than n, n is equal to N.

Find/-amin-30-ls # finds files accessed in the last 30 minutes of the system
Find/-atime-2-ls # finds files accessed in the last 48 hours of the system
Find/-mmin-10-ls # finds files that have been modified in the last 10 minutes of the system
Find/-mtime-1-ls # finds files that have been modified in the last 24 hours of the system
Find/-cmin-10-ls # finds files that have changed state in the last 10 minutes of the system
Find/-ctime-1-ls # finds files that have changed state in the last 24 hours of the system

# Remove all sub-files from the TMP directory 3 days ago, if not with *, it will kill this non-empty directory
/usr/bin/find/data/htdocs/test.cn/data/tmp/*-mtime +3-ls

[Under normal circumstances: the number of files found by atime and Mtime is equal]

Examples of shell scripts:

File name: test.sh

The contents are as follows:

# deleted three days ago, legacy dump file

day=$ (/bin/date +%y-%m-%d);
Count= '/usr/bin/find/data/htdocs/test.cn/data/tmp/*-mtime +3 | Wc-l ';
/usr/bin/find/data/htdocs/test.cn/data/tmp/*-mtime +3-delete;
Echo $day – $count;

#删除10天前的所有文件

find/tmp/*-type f-mtime +10-exec rm {} \;

#查找10天前的所有文件

find/tmp/*-type f-mtime +10-exec ls-l {} \;

can cooperate with script command, automatically delete android qq 15 days ago Picture cache

find/sdcard/tencent/*/*/.photo/*-type f-mtime +15-exec rm {} \;

Use Shell to delete files from three days ago or three days in Linux

Related Article

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.