Linux Delete files older than 3 days

Source: Internet
Author: User

4 down vote accepted

This is the easy enough (although note, goes by a modification time and than 3 days ago since a creation time is onl Y available on certain filesystems with special tools):

find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-delete

Remove the # before the once you be sure that it's finding the files you want to -delete remove.

To has it run by Cron, I would probably just create an executable script (add a shebang-to the top line of the #!bin/sh fi Le and make executable chmod a+x with), then put the it in a appropriate cron directory like /etc/cron.daily or /etc/cron.weekly . Provided of course that's you does not need a more specific schedule and that these directories exist on your distro.

Update

As noted below, the -delete option for find isn ' t very portable. A POSIX compatible approach would be:

find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-exec rm {} +

Again Remove the When is sure you has the right # files.

Update2

To quote from Stéphane Chazelas comment below:

Note that there is -exec rm {} + race condition vulnerabilities which -delete (where available) doesn ' t has. So don ' t use it on directories that is writeable by others. Some finds also has a that -execdir mitigates against those vulnerabilities.

Link:http://unix.stackexchange.com/questions/136804/cron-job-to-delete-files-older-than-3-days

Linux Delete files older than 3 days

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.