要求:删除linux下2天前的指定文件

find 文件
问题:在 tmp 目录下有大量包含 picture_* 的临时文件,每天晚上 2:00 对一天前的文件进行清理。之前在 crontab 下跑如下脚本,
但是发现脚本效率很低,每次执行时负载猛涨,影响到其他服务


#!/bin/sh
find /tmp -name "picture_*" -mtime +1 -exec rm -f {} ;
原因:目录下有大量文件,用 find 很耗资源。


解决:
#!/bin/sh
cd /tmp
time=`date -d "2 day ago" "+%b %d"`
ls -l | grep "picture" | grep "$time" | awk '{print $NF}' | xargs rm –rf
cd /tmp/pic
ls -l | grep "picture" | grep "$time" | awk '{print $NF}' | xargs rm -rf

相关文章:

  • 2021-11-16
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2021-06-15
  • 2021-11-02
  • 2021-08-15
  • 2021-04-27
  • 2021-11-23
  • 2021-11-29
相关资源
相似解决方案