自动从网络服务器中删除文件

2022-01-09 00:00:00 file webserver ftp php

我需要从我的网络服务器中的目录中删除文件,并且我需要一些脚本来自动执行此操作.而且需要满足的条件也很少.

I need to delete files from a directory in my web-server and I need some script to do it automatic. And there is few more conditions which need to be fulfilled.

  • 它必须清理目录然后总文件大小超过某些限制,例如 1.5GB
  • 该文件将每 24 小时删除一次.
  • 不会删除 10 ir 20 mins old 等新文件
  • 如果上述所有条件都能同时起作用,那就太棒了.
  • It has to clean the directory then total file size exceeds some certain limit for example 1,5GB
  • That files would be deleted every 24 hours.
  • New files like 10 ir 20 mins old would not be deleted
  • It would be just awesome if all of the conditions above would be work at the same time.

对于删除文件,我正在考虑某种玉米任务,但我对它们一无所知,所以这对我来说很棘手.
要删除文件,然后达到一定的限制,我在想某种 PHP 脚本是我的帮助.可能有专门用于这些东西的库.
无论如何,我都会很高兴得到任何帮助.也许我只是需要一些新鲜的想法来为谷歌想出一个正确的关键字;P

For deleting files I was thinking of some kind of corn task but I do not know a thing about them so it is tricky for me.
To delete files then a certain limit is reached I was thinking that some kind of PHP script my help. May be there is a library meant for these things.
Any way I will be very happy for any kind of help. May be I just need some fresh thoughts to come up with a right keyword for google ;P

我的服务器在 linux 上运行.

My server runs on linux.

推荐答案

如果你的服务器运行的是 linux,cron 作业是最好的选择.只需编写一个脚本来检查您提到的条件(使用例如 stat 和其他一些工具)并在适用时删除文件,并将 crond 设置为每 24 小时运行一次.这里是cron的简短介绍.

If your server is running linux, a cron job is the best option. Simply write a script that checks the conditions you mention (using e.g. stat and some other tools) and deletes the file if they apply, and set crond to run it every 24 hours. Here's a short introduction to cron.

在 Windows 上,您可以使用脚本和计划任务执行类似的操作.

On Windows, you'd do something similar with a script and a scheduled task.

相关文章