Linux regularly deletes files before N days

Use the find command: find path -mtime +days -type f -name “filename” -exec rm -rf {} \;

find /tmp -mtime +30 -type f -name "*" -exec rm -rf {} \;

Parameter analysis:
/tmp – set the directory to look up;
-mtime +30 – set the modification time to 30 days ago;
-type f – set the type of lookup to a file;
-name “*” – set the file name, you can use a wildcard;
-exec rm -rf – delete after the search is completed;
{} \; – fixed writing

This command is written into the script to achieve timed deletion.
find /tmp -mtime +30 -type f -name "*" -exec rm -rf {} \;

Configuration executable
chmod u+x ./

Configuring to crontab
crontab -e
0 0 * * * /home/username/ > /dev/null 2>&1

Automatic execution every day at zero

The first * indicates the minute in time. Value range: 0-59
The second * indicates the hour in time. Value range: 0-23
The third * indicates the day of the month, the range of values: 1-31
The fourth * indicates the first few months of the year, the range of values: 1-12
The fifth * indicates the day of the week, starting from Sunday, the value is 0 to 7, and 0 and 7 indicate Sunday.

reprinted the original text:Linux regularly deletes files before N days - CodeDay