Linux Bulk Delete Files by time (delete n days ago file)

Source: Internet
Author: User

It is necessary to delete the files under this directory according to time,/home/lifeccp/dicom/studies, and clean up the invalid data 20 days ago.

You can use the following command to complete:

Find /home/lifeccp/dicom/studies-mtime +"* *"rm -rf {} \;

This is deleted based on time.

The following is a brief explanation of the shell command:

Find/home/lifeccp/dicom/studies-mtime +21-name "* *"-exec RM-RF {} \;

    • /home/lifeccp/dicom/studies: Prepare any directory to be cleaned
    • -mtime: Standard statement notation
    • +10: Find the file 10 days ago, where the number represents the number of days, +30 means to find the file 30 days ago
    • "*. *": The type of data you want to find, "*.jpg" means looking for all files with the extension jpg, "*" means finding all files
    • -exec: Fixed notation
    • RM-RF: Forcibly deleting files, including directories
    • {} \; : fixed notation, pair of curly braces + space +/+;

Of course, according to the file name, according to the size, according to other different conditions to filter the deletion, or modify, etc., you can consider the sort command combined with. Because the time is limited, here is not to repeat, back to use when, I slowly add.

Linux Bulk Delete Files by time (delete n days ago file)

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.