How to delete regularly expired files in Linux

When managing files under Linux, we usually have the need to periodically delete expired files. For example, periodically delete log files that exceed a specified time. Otherwise, the longer it takes, the more space your log file will occupy your disk space.

In Linux, you can simply delete expired files with the command:

find /home/ddos -type f -mtime +30 -exec rm -f {} \;

Parameter:

  • /home/ddos is the path to find files
  • type f is to specify the file type as an ordinary file
  • -mtime +30 refers to the file whose modification time is 30 days from now
  • -exec rm -f means to delete the matched files without prompting.