Regularly delete files generated on the server disk every day

Since the program written will generate redundant files, I wrote a script to delete useless files regularly every day.

Problem: The interface program written will generate a file every time the interface is adjusted. Therefore, when the interface is adjusted many times a day, a large number of files will also be generated on the server.

Solution: Create a .sh text in the server configuration directory, that is, the etc directory, and write it with the vi editor:
#!/bin/bash
find /path that generates a large number of files -mtime 0 -name "file name (Note: You can use * instead of names, such as *.txt, a*.txt, *a.txt, etc.)" -exec rm -rf {} \;
Then enter: crontab -l in the root directory to view the scheduled task and create a timer Task input: crontab -e
and then use vi editor to write: 0 */2 * * * /etc/file name.sh

Note: 0 */2 * * * means to execute the task every two hours, that is to say every Delete redundant files once every two hours.
This time can also be modified, please Baidu.
The above means to delete redundant files every day, -mtime 0 time can be changed, refer to the following:

Linux find command mtime parameter usage
1. Current time 24 hours --- current time (yesterday-today)
#find . -mtime 0
2. Current Time 48 hours ago - current time 24 hours ago (the day before yesterday - yesterday)
#find . -mtime 1
3. Current time 48 hours ago (2 days ago)
#find . -mtime +1
4. Current time 24 hours - current time (yesterday-today)
#find . -mtime -1

N * 24
+1 means 1 * 24 + 24 hours outside..
+0 means 0 * 24 + 24 hours outside
1 means 1*24 + 24 to 24..
0 means 0 *24 + 24 to 0.
-1 means 0*24 +24, even for future time...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326454531&siteId=291194637