heshao2005 发表于 2018-8-19 09:44:41

shell脚本删除30天之前的备份文件实例

  根据公司要求,删除服务器30天之前的文件,如下是脚本:
  #vi del-30.sh
  #!/bin/bash
  location="/mpgdata/"
  find $location -type f -mtime +30 -exec rm -f {} \;
  #chmod +x del-30.sh
  说明:/mpgdata/是find查找备份文件的路径。
  -type f是指定文件类型为普通文件。
  -mtime +30是指30天之前的文件。
  -exec rm -f指执行静默删除匹配出来的文件。
  可将其加到自动任务里面,这样就可以做到自动清除了。
  #vi /etc/crontab
  59 11 28 * * root /root/del-30.sh    每月的28日11点59执行
  :wq
  #service crond restart

页: [1]
查看完整版本: shell脚本删除30天之前的备份文件实例